Initial checkin

This commit is contained in:
Thilo Karraß 2020-10-28 11:24:24 +01:00
commit 780ba51954
15 changed files with 4387 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

4
.idea/encodings.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

9
.idea/goboter.iml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Bundled Protobuf Distribution" level="application" />
</component>
</module>

View File

@ -0,0 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/goboter.iml" filepath="$PROJECT_DIR$/.idea/goboter.iml" />
</modules>
</component>
</project>

15
goboter.go Normal file
View File

@ -0,0 +1,15 @@
package goboter
import "udico.de/goboter/telegram"
//go:generate protoc -I proto/ proto/telegram.proto proto/telegram_response.proto proto/telegram_calls.proto --go_out=telegram
func NewTelegramBot(apikey, useragent string) *telegram.Bot {
return telegram.New(apikey, useragent)
}
// Mock!:q
func NewDiscordBot(token, useragent string) {
// dummy
}

433
proto/telegram.proto Normal file
View File

@ -0,0 +1,433 @@
syntax = "proto3";
package telegram;
// https://docs.google.com/spreadsheets/d/1Vm408AM5lW0h1qn187hH3wg5SSADXBUyg5JzcxX0M0Y/edit#gid=1959119128
// This object represents a Telegram user or bot.
message User {
int64 id = 1; // Unique identifier for this user or bot
bool is_bot = 2; // True, if this user is a bot
string first_name = 3; // Users or bots first name
string last_name = 4; // Optional. Users or bots last name
string username = 5; // Optional. Users or bots username
string language_code = 6; // Optional. IETF language tag of the user's language
}
// This object represents a chat.
message Chat {
int64 id = 1; // Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
string type = 2; // Type of chat, can be either private, group, supergroup or channel
string title = 3; // Optional. Title, for supergroups, channels and group chats
string username = 4; // Optional. Username, for private chats, supergroups and channels if available
string first_name = 5; // Optional. First name of the other party in a private chat
string last_name = 6; // Optional. Last name of the other party in a private chat
bool all_members_are_administrators = 7; // Optional. True if a group has All Members Are Admins enabled.
ChatPhoto photo = 8; // Optional. Chat photo. Returned only in getChat.
string description = 9; // Optional. Description, for supergroups and channel chats. Returned only in getChat.
string invite_link = 10; // Optional. Chat invite link, for supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.
Message pinned_message = 11; // Optional. Pinned message, for supergroups and channel chats. Returned only in getChat.
string sticker_set_name = 12; // Optional. For supergroups, name of group sticker set. Returned only in getChat.
bool can_set_sticker_set = 13; // Optional. True, if the bot can change the group sticker set. Returned only in getChat.
}
// This object represents a message.
message Message {
int64 message_id = 1; // Unique message identifier inside this chat
User from = 2; // Optional. Sender, empty for messages sent to channels
int64 date = 3; // Date the message was sent in Unix time
Chat chat = 4; // Conversation the message belongs to
User forward_from = 5; // Optional. For forwarded messages, sender of the original message
Chat forward_from_chat = 6; // Optional. For messages forwarded from channels, information about the original channel
int64 forward_from_message_id = 7; // Optional. For messages forwarded from channels, identifier of the original message in the channel
string forward_signature = 8; // Optional. For messages forwarded from channels, signature of the post author if present
int64 forward_date = 9; // Optional. For forwarded messages, date the original message was sent in Unix time
Message reply_to_message = 10; // Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
int64 edit_date = 11; // Optional. Date the message was last edited in Unix time
string media_group_id = 12; // Optional. The unique identifier of a media message group this message belongs to
string author_signature = 13; // Optional. Signature of the post author for messages in channels
string text = 14; // Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters.
repeated MessageEntity entities = 15; // Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
repeated MessageEntity caption_entities = 16; // Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
Audio audio = 17; // Optional. Message is an audio file, information about the file
Document document = 18; // Optional. Message is a general file, information about the file
Animation animation = 19; // Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
//Game game = 20; // Optional. Message is a game, information about the game. More about games »
repeated PhotoSize photo = 21; // Optional. Message is a photo, available sizes of the photo
Sticker sticker = 22; // Optional. Message is a sticker, information about the sticker
Video video = 23; // Optional. Message is a video, information about the video
Voice voice = 24; // Optional. Message is a voice message, information about the file
VideoNote video_note = 25; // Optional. Message is a video note, information about the video message
string caption = 26; // Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters
Contact contact = 27; // Optional. Message is a shared contact, information about the contact
Location location = 28; // Optional. Message is a shared location, information about the location
Venue venue = 29; // Optional. Message is a venue, information about the venue
repeated User new_chat_members = 30; // Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
User left_chat_member = 31; // Optional. A member was removed from the group, information about them (this member may be the bot itself)
string new_chat_title = 32; // Optional. A chat title was changed to this value
repeated PhotoSize new_chat_photo = 33; // Optional. A chat photo was change to this value
bool delete_chat_photo = 34; // Optional. Service message: the chat photo was deleted
bool group_chat_created = 35; // Optional. Service message: the group has been created
bool supergroup_chat_created = 36; // Optional. Service message: the supergroup has been created. This field cant be received in a message coming through updates, because bot cant be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
bool channel_chat_created = 37; // Optional. Service message: the channel has been created. This field cant be received in a message coming through updates, because bot cant be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
int64 migrate_to_chat_id = 38; // Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
int64 migrate_from_chat_id = 39; // Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
Message pinned_message = 40; // Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
//Invoice invoice = 41; // Optional. Message is an invoice for a payment, information about the invoice. More about payments »
//SuccessfulPayment successful_payment = 42; // Optional. Message is a service message about a successful payment, information about the payment. More about payments »
string connected_website = 43; // Optional. The domain name of the website on which the user has logged in. More about Telegram Login »
//PassportData passport_data = 44; // Optional. Telegram Passport data
}
// This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
message MessageEntity {
string type = 1; // Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link(for clickable text URLs), text_mention (for users without usernames)
int64 offset = 2; // Offset in UTF-16 code units to the start of the entity
int64 length = 3; // Length of the entity in UTF-16 code units
string url = 4; // Optional. For text_link only, url that will be opened after user taps on the text
User user = 5; // Optional. For text_mention only, the mentioned user
}
// This object represents one size of a photo or a file / sticker thumbnail.
message PhotoSize {
string file_id = 1; // Unique identifier for this file
int64 width = 2; // Photo width
int64 height = 3; // Photo height
int64 file_size = 4; // Optional. File size
}
// This object represents an audio file to be treated as music by the Telegram clients.
message Audio {
string file_id = 1; // Unique identifier for this file
int64 duration = 2; // Duration of the audio in seconds as defined by sender
string performer = 3; // Optional. Performer of the audio as defined by sender or by audio tags
string title = 4; // Optional. Title of the audio as defined by sender or by audio tags
string mime_type = 5; // Optional. MIME type of the file as defined by sender
int64 file_size = 6; // Optional. File size
PhotoSize thumb = 7; // Optional. Thumbnail of the album cover to which the music file belongs
}
// This object represents a general file (as opposed to photos, voice messages and audio files).
message Document {
string file_id = 1; // Unique file identifier
PhotoSize thumb = 2; // Optional. Document thumbnail as defined by sender
string file_name = 3; // Optional. Original filename as defined by sender
string mime_type = 4; // Optional. MIME type of the file as defined by sender
int64 file_size = 5; // Optional. File size
}
// This object represents a video file.
message Video {
string file_id = 1; // Unique identifier for this file
int64 width = 2; // Video width as defined by sender
int64 height = 3; // Video height as defined by sender
int64 duration = 4; // Duration of the video in seconds as defined by sender
PhotoSize thumb = 5; // Optional. Video thumbnail
string mime_type = 6; // Optional. Mime type of a file as defined by sender
int64 file_size = 7; // Optional. File size
}
// This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
message Animation {
string file_id = 1; // Unique file identifier
int64 width = 2; // Video width as defined by sender
int64 height = 3; // Video height as defined by sender
int64 duration = 4; // Duration of the video in seconds as defined by sender
PhotoSize thumb = 5; // Optional. Animation thumbnail as defined by sender
string file_name = 6; // Optional. Original animation filename as defined by sender
string mime_type = 7; // Optional. MIME type of the file as defined by sender
int64 file_size = 8; // Optional. File size
}
// This object represents a voice note.
message Voice {
string file_id = 1; // Unique identifier for this file
int64 duration = 2; // Duration of the audio in seconds as defined by sender
string mime_type = 3; // Optional. MIME type of the file as defined by sender
int64 file_size = 4; // Optional. File size
}
// This object represents a video message (available in Telegram apps as of v.4.0).
message VideoNote {
string file_id = 1; // Unique identifier for this file
int64 length = 2; // Video width and height (diameter of the video message) as defined by sender
int64 duration = 3; // Duration of the video in seconds as defined by sender
PhotoSize thumb = 4; // Optional. Video thumbnail
int64 file_size = 5; // Optional. File size
}
// This object represents a phone contact.
message Contact {
string phone_number = 1; // Contact's phone number
string first_name = 2; // Contact's first name
string last_name = 3; // Optional. Contact's last name
int64 user_id = 4; // Optional. Contact's user identifier in Telegram
string vcard = 5; // Optional. Additional data about the contact in the form of a vCard
}
// This object represents a point on the map.
message Location {
float longitude = 1; // Longitude as defined by sender
float latitude = 2; // Latitude as defined by sender
}
// This object represents a venue.
message Venue {
Location location = 1; // Venue location
string title = 2; // Name of the venue
string address = 3; // Address of the venue
string foursquare_id = 4; // Optional. Foursquare identifier of the venue
string foursquare_type = 5; // Optional. Foursquare type of the venue. (For example, arts_entertainment/default, arts_entertainment/aquarium or food/icecream.)
}
// This object represent a user's profile pictures.
message UserProfilePhotos {
int64 total_count = 1; // Total number of profile pictures the target user has
//Array of Array of PhotoSize photos = 2; // Requested profile pictures (in up to 4 sizes each)
}
// This object represents a file ready to be downloaded. The file can be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile.
message File {
string file_id = 1; // Unique identifier for this file
int64 file_size = 2; // Optional. File size, if known
string file_path = 3; // Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
}
// This object represents a custom keyboard with reply options (see Introduction to bots for details and examples).
message ReplyKeyboardMarkup {
//Array of Array of KeyboardButton keyboard = 1; // Array of button rows, each represented by an Array of KeyboardButton objects
bool resize_keyboard = 2; // Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
bool one_time_keyboard = 3; // Optional. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat the user can press a special button in the input field to see the custom keyboard again. Defaults to false.
bool selective = 4; // Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
// Example: A user requests to change the bots language, bot replies to the request with a keyboard to select the new language. Other users in the group dont see the keyboard.
}
// This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive.
message KeyboardButton {
string text = 1; // Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed
bool request_contact = 2; // Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
bool request_location = 3; // Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
}
// Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
message ReplyKeyboardRemove {
bool remove_keyboard = 1; // Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)
bool selective = 2; // Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
// Example: A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
}
// This object represents an inline keyboard that appears right next to the message it belongs to.
message InlineKeyboardMarkup {
//Array of Array of InlineKeyboardButton inline_keyboard = 1; // Array of button rows, each represented by an Array of InlineKeyboardButton objects
}
// This object represents one button of an inline keyboard. You must use exactly one of the optional fields.
message InlineKeyboardButton {
string text = 1; // Label text on the button
string url = 2; // Optional. HTTP or tg:// url to be opened when button is pressed
string callback_data = 3; // Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
string switch_inline_query = 4; // Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bots username and the specified inline query in the input field. Can be empty, in which case just the bots username will be inserted.
//Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm actions in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
string switch_inline_query_current_chat = 5; // Optional. If set, pressing the button will insert the bots username and the specified inline query in the current chat's input field. Can be empty, in which case only the bots username will be inserted.
//This offers a quick way for the user to open your bot in inline mode in the same chat good for selecting something from multiple options.
//CallbackGame callback_game = 6; // Optional. Description of the game that will be launched when the user presses the button.
// NOTE: This type of button must always be the first button in the first row.
bool pay = 7; // Optional. Specify True, to send a Pay button.
// NOTE: This type of button must always be the first button in the first row.
}
// This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_namewill be present.
message CallbackQuery {
string id = 1; // Unique identifier for this query
User from = 2; // Sender
Message message = 3; // Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
string inline_message_id = 4; // Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
string chat_instance = 5; // Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
string data = 6; // Optional. Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
string game_short_name = 7; // Optional. Short name of a Game to be returned, serves as the unique identifier for the game
}
// Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bots message and tapped Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
message ForceReply {
bool force_reply = 1; // Shows reply interface to the user, as if they manually selected the bots message and tapped Reply'
bool selective = 2; // Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
}
// This object represents a chat photo.
message ChatPhoto {
string small_file_id = 1; // Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download.
string big_file_id = 2; // Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download.
}
// This object contains information about one member of a chat.
message ChatMember {
User user = 1; // Information about the user
string status = 2; // The member's status in the chat. Can be creator, administrator, member, restricted, left or kicked
int64 until_date = 3; // Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
bool can_be_edited = 4; // Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
bool can_change_info = 5; // Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings
bool can_post_messages = 6; // Optional. Administrators only. True, if the administrator can post in the channel, channels only
bool can_edit_messages = 7; // Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only
bool can_delete_messages = 8; // Optional. Administrators only. True, if the administrator can delete messages of other users
bool can_invite_users = 9; // Optional. Administrators only. True, if the administrator can invite new users to the chat
bool can_restrict_members = 10; // Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
bool can_pin_messages = 11; // Optional. Administrators only. True, if the administrator can pin messages, supergroups only
bool can_promote_members = 12; // Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
bool can_send_messages = 13; // Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
bool can_send_media_messages = 14; // Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
bool can_send_other_messages = 15; // Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
bool can_add_web_page_previews = 16; // Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages
}
// Contains information about why a request was unsuccessful.
message ResponseParameters {
int64 migrate_to_chat_id = 1; // Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
int64 retry_after = 2; // Optional. In case of exceeding flood control, the number of seconds left to wait before the request can be repeated
}
// Represents a photo to be sent.
message InputMediaPhoto {
string type = 1; // Type of the result, must be photo
string media = 2; // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass attach://<file_attach_name> to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files »
string caption = 3; // Optional. Caption of the photo to be sent, 0-1024 characters
string parse_mode = 4; // Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
}
// Represents a video to be sent.
message InputMediaVideo {
string type = 1; // Type of the result, must be video
string media = 2; // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass attach://<file_attach_name> to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files »
//InputFile or String thumb = 3; // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnails width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
string caption = 4; // Optional. Caption of the video to be sent, 0-1024 characters
string parse_mode = 5; // Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
int64 width = 6; // Optional. Video width
int64 height = 7; // Optional. Video height
int64 duration = 8; // Optional. Video duration
bool supports_streaming = 9; // Optional. Pass True, if the uploaded video is suitable for streaming
}
// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
message InputMediaAnimation {
string type = 1; // Type of the result, must be animation
string media = 2; // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass attach://<file_attach_name> to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files »
//InputFile or String thumb = 3; // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnails width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
string caption = 4; // Optional. Caption of the animation to be sent, 0-1024 characters
string parse_mode = 5; // Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
int64 width = 6; // Optional. Animation width
int64 height = 7; // Optional. Animation height
int64 duration = 8; // Optional. Animation duration
}
// Represents an audio file to be treated as music to be sent.
message InputMediaAudio {
string type = 1; // Type of the result, must be audio
string media = 2; // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass attach://<file_attach_name> to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files »
//InputFile or String thumb = 3; // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnails width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
string caption = 4; // Optional. Caption of the audio to be sent, 0-1024 characters
string parse_mode = 5; // Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
int64 duration = 6; // Optional. Duration of the audio in seconds
string performer = 7; // Optional. Performer of the audio
string title = 8; // Optional. Title of the audio
}
// Represents a general file to be sent.
message InputMediaDocument {
string type = 1; // Type of the result, must be document
string media = 2; // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass attach://<file_attach_name> to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files »
//InputFile or String thumb = 3; // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnails width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
string caption = 4; // Optional. Caption of the document to be sent, 0-1024 characters
string parse_mode = 5; // Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
}
// This object represents a sticker.
message Sticker {
string file_id = 1; // Unique identifier for this file
int64 width = 2; // Sticker width
int64 height = 3; // Sticker height
PhotoSize thumb = 4; // Optional. Sticker thumbnail in the .webp or .jpg format
string emoji = 5; // Optional. Emoji associated with the sticker
string set_name = 6; // Optional. Name of the sticker set to which the sticker belongs
MaskPosition mask_position = 7; // Optional. For mask stickers, the position where the mask should be placed
int64 file_size = 8; // Optional. File size
}
// This object represents a sticker set.
message StickerSet {
string name = 1; // Sticker set name
string title = 2; // Sticker set title
bool contains_masks = 3; // True, if the sticker set contains masks
repeated Sticker stickers = 4; // List of all set stickers
}
// This object describes the position on faces where a mask should be placed by default.
message MaskPosition {
string point = 1; // The part of the face relative to which the mask should be placed. One of forehead, eyes, mouth, or chin.
float x_shift = 2; // Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position.
float y_shift = 3; // Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position.
float scale = 4; // Mask scaling coefficient. For example, 2.0 means double size.
}
// At most one of the optional parameters can be present in any given update.
message Update {
int64 update_id = 1; // The updates unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if youre using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.
Message message = 2; // Optional. New incoming message of any kind text, photo, sticker, etc.
Message edited_message = 3; // Optional. New version of a message that is known to the bot and was edited
Message channel_post = 4; // Optional. New incoming channel post of any kind text, photo, sticker, etc.
Message edited_channel_post = 5; // Optional. New version of a channel post that is known to the bot and was edited
InlineQuery inline_query = 6; // Optional. New incoming inline query
ChosenInlineResult chosen_inline_result = 7; // Optional. The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.
CallbackQuery callback_query = 8; // Optional. New incoming callback query
//ShippingQuery shipping_query = 9; // Optional. New incoming shipping query. Only for invoices with flexible price
//PreCheckoutQuery pre_checkout_query = 10; // Optional. New incoming pre-checkout query. Contains full information about checkout
}
// This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results.
message InlineQuery {
string id = 1; // Unique identifier for this query
User from = 2; // Sender
Location location = 3; // Optional. Sender location, only for bots that request user location
string query = 4; // Text of the query (up to 512 characters)
string offset = 5; // Offset of the results to be returned, can be controlled by the bot
}
// Represents a result of an inline query that was chosen by the user and sent to their chat partner.
message ChosenInlineResult {
string result_id = 1; // The unique identifier for the result that was chosen
User from = 2; // The user that chose the result
Location location = 3; // Optional. Sender location, only for bots that require user location
string inline_message_id = 4; // Optional. Identifier of the sent inline message. Available only if there is an inline keyboardattached to the message. Will be also received in callback queries and can be used to edit the message.
string query = 5; // The query that was used to obtain the result
}

View File

@ -0,0 +1,19 @@
syntax = "proto3";
package telegram;
import "telegram.proto";
import "telegram_response.proto";
message SendMessageParams {
enum ParseMode {
Markdown = 0;
HTML = 1;
}
int64 chat_id = 1; // Unique identifier for the target chat or username of the target channel (in the format @channelusername)
string text = 2 ; // Text of the message to be sent
ParseMode parse_mode = 3; // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
bool disable_web_page_preview = 4; // Disables link previews for links in this message
bool disable_notification = 5; // Sends the message silently. Users will receive a notification with no sound.
int64 reply_to_message_id = 6; // If the message is a reply, ID of the original message
}

View File

@ -0,0 +1,28 @@
syntax = "proto3";
package telegram;
import "telegram.proto";
message UserResponse {
bool ok = 1;
string description = 2; // Optional
int32 error_code = 3; // ok == false
ResponseParameters parameters = 4; // ok == false
User result = 5; // ok == true
}
message MessageResponse {
bool ok = 1;
string description = 2; // Optional
int32 error_code = 3; // ok == false
ResponseParameters parameters = 4; // ok == false
Message result = 5; // ok == true
}
message UpdateResponse {
bool ok = 1;
string description = 2; // Optional
int32 error_code = 3; // ok == false
ResponseParameters parameters = 4; // ok == false
repeated Update result = 5; // ok == true
}

113
telegram/bot.go Normal file
View File

@ -0,0 +1,113 @@
package telegram
import (
"context"
"fmt"
"github.com/pkg/errors"
"udico.de/cure"
)
type Bot struct {
// TODO: check if this is really required, since we also hold the key in the api caller
key string
api *cure.Endpoint
// Remember to call Poll, or Listen
Updates chan *Update
updateid int64
}
func New(apikey, useragent string) *Bot {
ret := &Bot{
key: apikey,
api: cure.New(fmt.Sprintf("https://api.telegram.org/bot%v", apikey)),
Updates: make(chan *Update),
}
ret.api.UserAgent = useragent
return ret
}
// Basically a ping at the telegram API.
// Gets information about the Bot user.
func (b *Bot) Me() (*User, error) {
call := b.api.Get("/getMe")
ret := &UserResponse{}
err := call.Fire(context.Background(), ret)
if !err.Ok() {
return nil, err.Error()
}
if !ret.Ok {
e := ret.Description
if ret.ErrorCode > 0 {
e = fmt.Sprintf("%v [code: %v]", e, ret.ErrorCode)
}
return nil, errors.New(e)
}
return ret.Result, err.Error()
}
func (b *Bot) GetUpdates(ctx context.Context, offset, limit, timeout int64) ([]*Update, error) {
call := b.api.Get("/getUpdates")
call.Parameters["offset"] = fmt.Sprintf("%v", offset)
call.Parameters["limit"] = fmt.Sprintf("%v", limit)
call.Parameters["timeout"] = fmt.Sprintf("%v", timeout)
ret := &UpdateResponse{}
err := call.Fire(ctx, ret)
if !err.Ok() {
return nil, err.Error()
}
if !ret.Ok {
e := ret.Description
if ret.ErrorCode > 0 {
e = fmt.Sprintf("%v [code: %v]", e, ret.ErrorCode)
}
return nil, errors.New(e)
}
return ret.Result, err.Error()
}
func (b *Bot) SendMessage(chatid int64, message string, replyto int64) (*Message, error) {
call := b.api.PostForm("/sendMessage")
//prm := &SendMessageParams{
// ChatId: chatid,
// Text: message,
// ReplyToMessageId: replyto,
//}
//call.Param(prm)
call.Parameters["chat_id"] = fmt.Sprintf("%v", chatid)
call.Parameters["text"] = message
ret := &MessageResponse{}
err := call.Fire(context.Background(), ret)
if !err.Ok() {
return nil, err.Error()
}
if !ret.Ok {
e := ret.Description
if ret.ErrorCode > 0 {
e = fmt.Sprintf("%v [code: %v]", e, ret.ErrorCode)
}
return nil, errors.New(e)
}
return ret.Result, err.Error()
}
func (b *Bot) EditMessageText(chatid int64, messageid int64, message string) (*Message, error) {
call := b.api.PostForm( "/editMessageText")
call.Parameters["chat_id"] = fmt.Sprintf("%v", chatid)
call.Parameters["message_id"] = fmt.Sprintf("%v", messageid)
call.Parameters["text"] = message
ret := &MessageResponse{}
err := call.Fire(context.Background(), ret)
if !err.Ok() {
return nil, err.Error()
}
if !ret.Ok {
e := ret.Description
if ret.ErrorCode > 0 {
e = fmt.Sprintf("%v [code: %v]", e, ret.ErrorCode)
}
return nil, errors.New(e)
}
return ret.Result, err.Error()
}

3255
telegram/telegram.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: telegram_calls.proto
package telegram
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type SendMessageParams_ParseMode int32
const (
SendMessageParams_Markdown SendMessageParams_ParseMode = 0
SendMessageParams_HTML SendMessageParams_ParseMode = 1
)
var SendMessageParams_ParseMode_name = map[int32]string{
0: "Markdown",
1: "HTML",
}
var SendMessageParams_ParseMode_value = map[string]int32{
"Markdown": 0,
"HTML": 1,
}
func (x SendMessageParams_ParseMode) String() string {
return proto.EnumName(SendMessageParams_ParseMode_name, int32(x))
}
func (SendMessageParams_ParseMode) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_4d032b4523f3bd85, []int{0, 0}
}
type SendMessageParams struct {
ChatId int64 `protobuf:"varint,1,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"`
ParseMode SendMessageParams_ParseMode `protobuf:"varint,3,opt,name=parse_mode,json=parseMode,proto3,enum=telegram.SendMessageParams_ParseMode" json:"parse_mode,omitempty"`
DisableWebPagePreview bool `protobuf:"varint,4,opt,name=disable_web_page_preview,json=disableWebPagePreview,proto3" json:"disable_web_page_preview,omitempty"`
DisableNotification bool `protobuf:"varint,5,opt,name=disable_notification,json=disableNotification,proto3" json:"disable_notification,omitempty"`
ReplyToMessageId int64 `protobuf:"varint,6,opt,name=reply_to_message_id,json=replyToMessageId,proto3" json:"reply_to_message_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *SendMessageParams) Reset() { *m = SendMessageParams{} }
func (m *SendMessageParams) String() string { return proto.CompactTextString(m) }
func (*SendMessageParams) ProtoMessage() {}
func (*SendMessageParams) Descriptor() ([]byte, []int) {
return fileDescriptor_4d032b4523f3bd85, []int{0}
}
func (m *SendMessageParams) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_SendMessageParams.Unmarshal(m, b)
}
func (m *SendMessageParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_SendMessageParams.Marshal(b, m, deterministic)
}
func (m *SendMessageParams) XXX_Merge(src proto.Message) {
xxx_messageInfo_SendMessageParams.Merge(m, src)
}
func (m *SendMessageParams) XXX_Size() int {
return xxx_messageInfo_SendMessageParams.Size(m)
}
func (m *SendMessageParams) XXX_DiscardUnknown() {
xxx_messageInfo_SendMessageParams.DiscardUnknown(m)
}
var xxx_messageInfo_SendMessageParams proto.InternalMessageInfo
func (m *SendMessageParams) GetChatId() int64 {
if m != nil {
return m.ChatId
}
return 0
}
func (m *SendMessageParams) GetText() string {
if m != nil {
return m.Text
}
return ""
}
func (m *SendMessageParams) GetParseMode() SendMessageParams_ParseMode {
if m != nil {
return m.ParseMode
}
return SendMessageParams_Markdown
}
func (m *SendMessageParams) GetDisableWebPagePreview() bool {
if m != nil {
return m.DisableWebPagePreview
}
return false
}
func (m *SendMessageParams) GetDisableNotification() bool {
if m != nil {
return m.DisableNotification
}
return false
}
func (m *SendMessageParams) GetReplyToMessageId() int64 {
if m != nil {
return m.ReplyToMessageId
}
return 0
}
func init() {
proto.RegisterEnum("telegram.SendMessageParams_ParseMode", SendMessageParams_ParseMode_name, SendMessageParams_ParseMode_value)
proto.RegisterType((*SendMessageParams)(nil), "telegram.SendMessageParams")
}
func init() { proto.RegisterFile("telegram_calls.proto", fileDescriptor_4d032b4523f3bd85) }
var fileDescriptor_4d032b4523f3bd85 = []byte{
// 294 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x90, 0x4f, 0x4b, 0x33, 0x31,
0x10, 0x87, 0xdf, 0xb4, 0x7d, 0xeb, 0x76, 0x90, 0x52, 0xd3, 0x4a, 0x43, 0x4f, 0x4b, 0x45, 0xd8,
0x8b, 0x05, 0xf5, 0xe0, 0x17, 0xf0, 0x60, 0xc1, 0x95, 0xb2, 0x16, 0x3c, 0x86, 0x6c, 0x33, 0xd6,
0xe0, 0xee, 0x26, 0x24, 0xc1, 0xd5, 0x2f, 0xe8, 0xe7, 0x92, 0xfd, 0x8b, 0xe0, 0xed, 0x97, 0x3c,
0x33, 0xc3, 0x33, 0x03, 0x0b, 0x8f, 0x19, 0x1e, 0xad, 0xc8, 0xf9, 0x41, 0x64, 0x99, 0xdb, 0x18,
0xab, 0xbd, 0xa6, 0x41, 0xf7, 0xbb, 0x9a, 0x76, 0xa9, 0x21, 0xab, 0x65, 0x5f, 0x6f, 0xd1, 0x19,
0x5d, 0x38, 0x6c, 0xc0, 0xfa, 0x7b, 0x00, 0x67, 0xcf, 0x58, 0xc8, 0x18, 0x9d, 0x13, 0x47, 0xdc,
0x09, 0x2b, 0x72, 0x47, 0x97, 0x70, 0x72, 0x78, 0x13, 0x9e, 0x2b, 0xc9, 0x48, 0x48, 0xa2, 0x61,
0x32, 0xae, 0x9e, 0x5b, 0x49, 0x29, 0x8c, 0x3c, 0x7e, 0x7a, 0x36, 0x08, 0x49, 0x34, 0x49, 0xea,
0x4c, 0xef, 0x01, 0x8c, 0xb0, 0x0e, 0x79, 0xae, 0x25, 0xb2, 0x61, 0x48, 0xa2, 0xe9, 0xcd, 0xe5,
0xa6, 0x17, 0xf8, 0x33, 0x7d, 0xb3, 0xab, 0xaa, 0x63, 0x2d, 0x31, 0x99, 0x98, 0x2e, 0xd2, 0x3b,
0x60, 0x52, 0x39, 0x91, 0x66, 0xc8, 0x4b, 0x4c, 0xb9, 0x11, 0x47, 0xe4, 0xc6, 0xe2, 0x87, 0xc2,
0x92, 0x8d, 0x42, 0x12, 0x05, 0xc9, 0x79, 0xcb, 0x5f, 0x30, 0xdd, 0x55, 0xc3, 0x1a, 0x48, 0xaf,
0x61, 0xd1, 0x35, 0x16, 0xda, 0xab, 0x57, 0x75, 0x10, 0x5e, 0xe9, 0x82, 0xfd, 0xaf, 0x9b, 0xe6,
0x2d, 0x7b, 0xfa, 0x85, 0xe8, 0x15, 0xcc, 0x2d, 0x9a, 0xec, 0x8b, 0x7b, 0xcd, 0xf3, 0x46, 0xad,
0x5a, 0x75, 0x5c, 0xaf, 0x3a, 0xab, 0xd1, 0x5e, 0xb7, 0xce, 0x5b, 0xb9, 0xbe, 0x80, 0x49, 0xaf,
0x4c, 0x4f, 0x21, 0x88, 0x85, 0x7d, 0x97, 0xba, 0x2c, 0x66, 0xff, 0x68, 0x00, 0xa3, 0x87, 0x7d,
0xfc, 0x38, 0x23, 0xe9, 0xb8, 0xbe, 0xe7, 0xed, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x9f,
0xee, 0x7e, 0x9a, 0x01, 0x00, 0x00,
}

View File

@ -0,0 +1,262 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: telegram_response.proto
package telegram
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type UserResponse struct {
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
ErrorCode int32 `protobuf:"varint,3,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
Parameters *ResponseParameters `protobuf:"bytes,4,opt,name=parameters,proto3" json:"parameters,omitempty"`
Result *User `protobuf:"bytes,5,opt,name=result,proto3" json:"result,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UserResponse) Reset() { *m = UserResponse{} }
func (m *UserResponse) String() string { return proto.CompactTextString(m) }
func (*UserResponse) ProtoMessage() {}
func (*UserResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_9002cdf246284807, []int{0}
}
func (m *UserResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UserResponse.Unmarshal(m, b)
}
func (m *UserResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UserResponse.Marshal(b, m, deterministic)
}
func (m *UserResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_UserResponse.Merge(m, src)
}
func (m *UserResponse) XXX_Size() int {
return xxx_messageInfo_UserResponse.Size(m)
}
func (m *UserResponse) XXX_DiscardUnknown() {
xxx_messageInfo_UserResponse.DiscardUnknown(m)
}
var xxx_messageInfo_UserResponse proto.InternalMessageInfo
func (m *UserResponse) GetOk() bool {
if m != nil {
return m.Ok
}
return false
}
func (m *UserResponse) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *UserResponse) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *UserResponse) GetParameters() *ResponseParameters {
if m != nil {
return m.Parameters
}
return nil
}
func (m *UserResponse) GetResult() *User {
if m != nil {
return m.Result
}
return nil
}
type MessageResponse struct {
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
ErrorCode int32 `protobuf:"varint,3,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
Parameters *ResponseParameters `protobuf:"bytes,4,opt,name=parameters,proto3" json:"parameters,omitempty"`
Result *Message `protobuf:"bytes,5,opt,name=result,proto3" json:"result,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *MessageResponse) Reset() { *m = MessageResponse{} }
func (m *MessageResponse) String() string { return proto.CompactTextString(m) }
func (*MessageResponse) ProtoMessage() {}
func (*MessageResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_9002cdf246284807, []int{1}
}
func (m *MessageResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_MessageResponse.Unmarshal(m, b)
}
func (m *MessageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_MessageResponse.Marshal(b, m, deterministic)
}
func (m *MessageResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_MessageResponse.Merge(m, src)
}
func (m *MessageResponse) XXX_Size() int {
return xxx_messageInfo_MessageResponse.Size(m)
}
func (m *MessageResponse) XXX_DiscardUnknown() {
xxx_messageInfo_MessageResponse.DiscardUnknown(m)
}
var xxx_messageInfo_MessageResponse proto.InternalMessageInfo
func (m *MessageResponse) GetOk() bool {
if m != nil {
return m.Ok
}
return false
}
func (m *MessageResponse) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *MessageResponse) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *MessageResponse) GetParameters() *ResponseParameters {
if m != nil {
return m.Parameters
}
return nil
}
func (m *MessageResponse) GetResult() *Message {
if m != nil {
return m.Result
}
return nil
}
type UpdateResponse struct {
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
ErrorCode int32 `protobuf:"varint,3,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
Parameters *ResponseParameters `protobuf:"bytes,4,opt,name=parameters,proto3" json:"parameters,omitempty"`
Result []*Update `protobuf:"bytes,5,rep,name=result,proto3" json:"result,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UpdateResponse) Reset() { *m = UpdateResponse{} }
func (m *UpdateResponse) String() string { return proto.CompactTextString(m) }
func (*UpdateResponse) ProtoMessage() {}
func (*UpdateResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_9002cdf246284807, []int{2}
}
func (m *UpdateResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UpdateResponse.Unmarshal(m, b)
}
func (m *UpdateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UpdateResponse.Marshal(b, m, deterministic)
}
func (m *UpdateResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_UpdateResponse.Merge(m, src)
}
func (m *UpdateResponse) XXX_Size() int {
return xxx_messageInfo_UpdateResponse.Size(m)
}
func (m *UpdateResponse) XXX_DiscardUnknown() {
xxx_messageInfo_UpdateResponse.DiscardUnknown(m)
}
var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo
func (m *UpdateResponse) GetOk() bool {
if m != nil {
return m.Ok
}
return false
}
func (m *UpdateResponse) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *UpdateResponse) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *UpdateResponse) GetParameters() *ResponseParameters {
if m != nil {
return m.Parameters
}
return nil
}
func (m *UpdateResponse) GetResult() []*Update {
if m != nil {
return m.Result
}
return nil
}
func init() {
proto.RegisterType((*UserResponse)(nil), "telegram.UserResponse")
proto.RegisterType((*MessageResponse)(nil), "telegram.MessageResponse")
proto.RegisterType((*UpdateResponse)(nil), "telegram.UpdateResponse")
}
func init() { proto.RegisterFile("telegram_response.proto", fileDescriptor_9002cdf246284807) }
var fileDescriptor_9002cdf246284807 = []byte{
// 246 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x92, 0xcf, 0x4a, 0x03, 0x31,
0x10, 0xc6, 0xc9, 0xd6, 0x96, 0x76, 0x56, 0x56, 0xcd, 0xc5, 0x20, 0x0a, 0xa1, 0x07, 0x89, 0x97,
0x1e, 0xea, 0xd5, 0x9b, 0x67, 0x41, 0x02, 0x3d, 0x97, 0xd8, 0x1d, 0x4a, 0xe9, 0x9f, 0x09, 0x33,
0xf1, 0x11, 0x3d, 0x88, 0x2f, 0x25, 0x6c, 0x37, 0xed, 0xd2, 0x27, 0xd8, 0x5b, 0x98, 0x6f, 0x3e,
0xf2, 0xfb, 0x91, 0xc0, 0x7d, 0xc2, 0x1d, 0xae, 0x39, 0xec, 0x97, 0x8c, 0x12, 0xe9, 0x20, 0x38,
0x8b, 0x4c, 0x89, 0xf4, 0x38, 0x07, 0x0f, 0x55, 0x3e, 0x1d, 0x93, 0xe9, 0x8f, 0x82, 0xeb, 0x85,
0x20, 0xfb, 0xb6, 0xa0, 0x2b, 0x28, 0x68, 0x6b, 0x94, 0x55, 0x6e, 0xec, 0x0b, 0xda, 0x6a, 0x0b,
0x65, 0x8d, 0xb2, 0xe2, 0x4d, 0x4c, 0x1b, 0x3a, 0x98, 0xc2, 0x2a, 0x37, 0xf1, 0xdd, 0x91, 0x7e,
0x02, 0x40, 0x66, 0xe2, 0xe5, 0x8a, 0x6a, 0x34, 0x03, 0xab, 0xdc, 0xd0, 0x4f, 0x9a, 0xc9, 0x3b,
0xd5, 0xa8, 0xdf, 0x00, 0x62, 0xe0, 0xb0, 0xc7, 0x84, 0x2c, 0xe6, 0xca, 0x2a, 0x57, 0xce, 0x1f,
0x67, 0x27, 0x8c, 0x7c, 0xf1, 0xe7, 0x69, 0xc7, 0x77, 0xf6, 0xf5, 0x33, 0x8c, 0x18, 0xe5, 0x7b,
0x97, 0xcc, 0xb0, 0x69, 0x56, 0xe7, 0x66, 0x83, 0xdd, 0xa6, 0xd3, 0x3f, 0x05, 0x37, 0x1f, 0x28,
0x12, 0xd6, 0xd8, 0x57, 0x95, 0x97, 0x0b, 0x95, 0xbb, 0x73, 0x33, 0x93, 0x67, 0x9b, 0x5f, 0x05,
0xd5, 0x22, 0xd6, 0x21, 0xf5, 0x56, 0xc6, 0x75, 0x64, 0x06, 0xae, 0x9c, 0xdf, 0x76, 0xde, 0xe5,
0x08, 0xde, 0xe6, 0x5f, 0xa3, 0xe6, 0xa3, 0xbd, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x4b,
0x1c, 0x4a, 0x9d, 0x02, 0x00, 0x00,
}

62
telegram/update.go Normal file
View File

@ -0,0 +1,62 @@
package telegram
import (
"context"
"github.com/sirupsen/logrus"
"time"
)
// Serve the Update channel using short polls every <intervall> milliseconds
func (b *Bot) ShortPoll(ctx context.Context, interval int) {
cTicker := time.NewTicker(time.Millisecond * time.Duration(interval)).C
for {
select {
case _, ok := <-ctx.Done():
if ok {
// nope! send on the quit channel is eeeeevil!
}
return
case <-cTicker:
// do an update
updates, err := b.GetUpdates(ctx, b.updateid, 100, 0)
if err != nil {
logrus.WithError(err).Error("cannot get updates")
return // maybe just try to go on?
} else {
for _, u := range updates {
update := u
if update.UpdateId >= b.updateid {
b.updateid = update.UpdateId + 1
}
b.Updates <- update
}
}
}
}
}
// Serve the Update channel using long polling
func (b *Bot) LongPoll(ctx context.Context, timeout int64) {
for {
select {
case <-ctx.Done():
return
default:
updates, err := b.GetUpdates(ctx, b.updateid, 100, timeout)
if err != nil {
logrus.WithError(err).Error("cannot get updates")
return // maybe just try to go on?
} else {
for _, u := range updates {
update := u
if update.UpdateId >= b.updateid {
b.updateid = update.UpdateId + 1
}
b.Updates <- update
}
}
}
}
}
// webhook