-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (69 loc) · 9.84 KB
/
Copy pathmain.cpp
File metadata and controls
85 lines (69 loc) · 9.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "qcoreapplication.h"
#include "TelegramBotAPI.h"
using namespace Telegram;
int main(int argc, char* argv[]) {
QCoreApplication coreApplication(argc, argv);
Bot telegram_bot;
// Telegram::Bot::errorOccured is emitted every time when the negative response is received from the Telegram server and holds an Error object in arguments. Error class contains the occurred error description and code. See Error.h for details
QObject::connect(&telegram_bot, &Bot::errorOccured, [](Error error) {
qDebug() << "\n" << "--| Error occured:"
<< "\n" << "Error code: " << error.error_code
<< "\n" << "Description: " << error.description;
});
// Telegram::Bot::networkErrorOccured is emitted every time when there is an error while receiving Updates from the Telegram. Error class contains the occurred error description and code. See Error.h for details
QObject::connect(&telegram_bot, &Bot::networkErrorOccured, [](Error error) {
qDebug() << "\n" << "--| Network error occured:"
<< "\n" << "Error code: " << error.error_code
<< "\n" << "Description: " << error.description;
});
// Whenever the user types "@bot_username" and some text after it in any chat - your bot receives an incoming inline query, it can be obtained via Telegram::Bot::inlineQueryReceived() signal. This query holds a text that the user wrote and a lot of additional information about this query. See InlineQuery.h for more details
// You can answer this query using Telegram::Bot::answerInlineQuery() method to show some results to the user. You can send up to 50 results in answer to a query
//
// Full list of all existing types of result listed below. See header file of every result type or the official Telegram Bot API documentation for more details
// ● InlineQueryResultCachedAudio - Represents a link to an MP3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
// ● InlineQueryResultCachedDocument - Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file
// ● InlineQueryResultCachedGif - Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation
// ● InlineQueryResultCachedMpeg4Gif - Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation
// ● InlineQueryResultCachedPhoto - Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo
// ● InlineQueryResultCachedSticker - Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker
// ● InlineQueryResultCachedVideo - Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video
// ● InlineQueryResultCachedVoice - Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message
// ● InlineQueryResultArticle - Represents a link to an article or web page
// ● InlineQueryResultAudio - Represents a link to an MP3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio
// ● InlineQueryResultContact - Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact
// ● InlineQueryResultGame - Represents a Game
// ● InlineQueryResultDocument - Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method
// ● InlineQueryResultGif - Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation
// ● InlineQueryResultLocation - Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location
// ● InlineQueryResultMpeg4Gif - Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation
// ● InlineQueryResultPhoto - Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo
// ● InlineQueryResultVenue - Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue
// ● InlineQueryResultVideo - Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video
// ● InlineQueryResultVoice - Represents a link to a voice recording in an .OGG container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message
//
//
// Also you can specify input_message_content argument. It represents a message that will be sent as a result when the user chooses some of the inline query results. Telegram clients currently support the following 5 types:
// ● InputTextMessageContent - Represents the content of a text message to be sent as the result of an inline query
// ● InputLocationMessageContent - Represents the content of a location message to be sent as the result of an inline query
// ● InputVenueMessageContent - Represents the content of a venue message to be sent as the result of an inline query
// ● InputContactMessageContent - Represents the content of a contact message to be sent as the result of an inline query
// ● InputInvoiceMessageContent - Represents the content of an invoice message to be sent as the result of an inline query
//
//
// You can collect "feedback" what inline results users are choosing. To know which of the provided results your users are sending to their chat partners, send @Botfather the /setinlinefeedback command. With this enabled, you will receive the results chosen by your users via Telegram::Bot::chosenInlineResult() signal.
// > NOTE: This can create load issues for popular bots. You may receive more results than actual requests due to caching(see the cache_time parameter in answerInlineQuery). For these cases, we recommend adjusting the probability setting to receive 1 / 10, 1 / 100 or 1 / 1000 of the results.
// In this example we will simply answer to an incoming inline query with couple of existing inline query results
// Telegram::Bot::inlineQueryReceived() emitted every time when new inline query is received. Let's connect it to the lambda where we handle this inline query
QObject::connect(&telegram_bot, &Bot::inlineQueryReceived, [&](qint32 update_id, InlineQuery inline_query) {
// If the user has typed "@bot_username cached audio" we will reply with InlineQueryResultCachedAudio
if (inline_query.query.toLower() == "cached audio")
telegram_bot.answerInlineQuery(inline_query.id, { std::make_shared<InlineQueryResultCachedAudio>("cached_audio_test_id", "CQACAgIAAxkDAAIDoWGP-KnkOzAbLi5gkTWtX5N2kI5iAAI9FQACLNiASEtlh9RXqNf0IgQ").get() });
// If the user has typed "@bot_username cached photo" we will reply with InlineQueryResultCachedPhoto
if (inline_query.query.toLower() == "cached photo")
telegram_bot.answerInlineQuery(inline_query.id, { std::make_shared<InlineQueryResultCachedPhoto>("cached_photo_test_id", "AgACAgIAAxkDAAIDsWGP-yniee-gNjSiQm9rGyFN2difAAJ7tzEb-ctJSH1nSWMEWCf9AQADAgADeAADIgQ").get() });
// If the user has typed "@bot_username cached gif" we will reply with InlineQueryResultCachedGif
if (inline_query.query.toLower() == "cached gif")
telegram_bot.answerInlineQuery(inline_query.id, { std::make_shared<InlineQueryResultCachedGif>("cached_gif_test_id", "CgACAgIAAxkDAAIDqWGP-SPZBB3jSoVtxNGC50vXZu2xAAJHFQACLNiASET0fbOGrYffIgQ").get() });
});
return coreApplication.exec();
}