|
| 1 | +Bot |
| 2 | +=== |
| 3 | + |
| 4 | +This object represents a Telegram bot. |
| 5 | + |
| 6 | +.. warning:: |
| 7 | + The Bot object and its attributes should remain unchanged after it has been initialized. |
| 8 | + |
| 9 | +========== |
| 10 | +Bot(token) |
| 11 | +========== |
| 12 | + |
| 13 | +* ``token`` <String> A valid token for the Telegram Bot API |
| 14 | + |
| 15 | +Creates a new Bot object and fetches basic information about it (aysncronous call to Telegram's ``getMe`` method). |
| 16 | + |
| 17 | +.. _init: |
| 18 | + |
| 19 | +====== |
| 20 | +init() |
| 21 | +====== |
| 22 | + |
| 23 | +Starts fetching updates for the bot. |
| 24 | + |
| 25 | +============ |
| 26 | +getUpdates() |
| 27 | +============ |
| 28 | + |
| 29 | +Retrieves updates for the bot from the Telegram API and processes them. This function is called by :ref:`init` and |
| 30 | +shouldn't be called manually. The first call made by the bot will be with a -1 offset that will erase any backlog updates. |
| 31 | +Updates older than 2 seconds are also ignored. Updates are retrieved 100 at a time, with a 30 seconds timeout. |
| 32 | + |
| 33 | +======================================= |
| 34 | +command(command, description, callback) |
| 35 | +======================================= |
| 36 | + |
| 37 | +* ``command`` <String> The command, without the opening / |
| 38 | +* ``description`` <String> The command's description, will be used for the /help message |
| 39 | +* ``callback`` <Function> This function will be called whenever the command is triggered with an array of arguments ``args`` along with the :doc:`Message` ``message`` responsible for triggering the command |
| 40 | + |
| 41 | +Registers a command handler for the specified ``command``, with the provided ``description`` and ``callback``, also |
| 42 | +adding the command to the /help message. |
| 43 | + |
| 44 | +================ |
| 45 | +getChat(chat_id) |
| 46 | +================ |
| 47 | + |
| 48 | +* ``chat_id`` <String> |
| 49 | + |
| 50 | +Returns a promise that resolves to the :doc:`Chat` object of the requested chat. |
| 51 | + |
| 52 | +================== |
| 53 | +leaveChat(chat_id) |
| 54 | +================== |
| 55 | + |
| 56 | +* ``chat_id`` <String>|<Chat> |
| 57 | + |
| 58 | +Leaves the chat and returns a promise that resolves to the response (according to Telegram, true on success). |
| 59 | + |
| 60 | +=================================== |
| 61 | +sendMessage(chat_id, text, options) |
| 62 | +=================================== |
| 63 | + |
| 64 | +* ``chat_id`` <String>|<Chat>|<User> |
| 65 | +* ``text`` <String> |
| 66 | +* ``options`` <Object> *Optional* |
| 67 | + |
| 68 | +Sends a message to the specified chat and returns a promise that resolves to a :doc:`Message` object representing what has |
| 69 | +been sent. |
| 70 | + |
| 71 | +=================================================== |
| 72 | +sendLocation(chat_id, longitude, latitude, options) |
| 73 | +=================================================== |
| 74 | + |
| 75 | +* ``chat_id`` <String>|<Chat>|<User> |
| 76 | +* ``longitude`` <Number> |
| 77 | +* ``latitude`` <Number> |
| 78 | +* ``options`` <Object> *Optional* |
| 79 | + |
| 80 | +Sends a location object to the specified chat and returns a promise that resolves to a :doc:`Message` object representing what |
| 81 | +has been sent. |
| 82 | + |
| 83 | +================================================================ |
| 84 | +sendVenue(chat_id, longitude, latitude, title, address, options) |
| 85 | +================================================================ |
| 86 | + |
| 87 | +* ``chat_id`` <String>|<Chat>|<User> |
| 88 | +* ``longitude`` <Number> |
| 89 | +* ``latitude`` <Number> |
| 90 | +* ``title`` <String> |
| 91 | +* ``address`` <String> |
| 92 | +* ``options`` <Object> *Optional* |
| 93 | + |
| 94 | +Sends a venue object to the specified chat and returns a promise that resolves to a :doc:`Message` object representing what has |
| 95 | +been sent. |
| 96 | + |
| 97 | +======================================================= |
| 98 | +sendContact(chat_id, phone_number, first_name, options) |
| 99 | +======================================================= |
| 100 | + |
| 101 | +* ``chat_id`` <String>|<Chat>|<User> |
| 102 | +* ``phone_number`` <String> |
| 103 | +* ``first_name`` <String> |
| 104 | +* ``options`` <Object> *Optional* |
| 105 | + |
| 106 | +Sends a contact object to the specified chat and returns a promise that resolves to a :doc:`Message` object representing what has |
| 107 | +been sent. |
| 108 | + |
| 109 | +========================================================== |
| 110 | +forwardMessage(chat_id, from_chat_id, message_id, options) |
| 111 | +========================================================== |
| 112 | + |
| 113 | +* ``chat_id`` <String>|<Chat>|<User> |
| 114 | +* ``from_chat_id`` <String> |
| 115 | +* ``message_id`` <String> |
| 116 | +* ``options`` <Object> *Optional* |
| 117 | + |
| 118 | +Forwards a message to the specified chat and returns a promise that resolves to a :doc:`Message` object representing what has |
| 119 | +been sent. |
| 120 | + |
| 121 | +==================================== |
| 122 | +answerCallbackQuery(id, text, alert) |
| 123 | +==================================== |
| 124 | + |
| 125 | +* ``id`` <String> |
| 126 | +* ``text`` <String> |
| 127 | +* ``alert`` <Boolean> Whether the user should be shown an alert |
| 128 | + |
| 129 | +Answers a callback query and returns a promise that resolves to the response (according to Telegram, true on success). |
| 130 | + |
| 131 | +====================================== |
| 132 | +getUserProfilePhotos(user_id, options) |
| 133 | +====================================== |
| 134 | + |
| 135 | +* ``user_id`` <String>|<User> |
| 136 | +* ``options`` <Object> *Optional* |
| 137 | + |
| 138 | +Returns a promise that resolves to a :doc:`UserProfilePhotos` object. |
| 139 | + |
| 140 | +================ |
| 141 | +getFile(file_id) |
| 142 | +================ |
| 143 | + |
| 144 | +* ``file_id`` <String> |
| 145 | + |
| 146 | +Returns a promise that resolves to a :doc:`File` object. |
| 147 | + |
| 148 | +====================================== |
| 149 | +sendFile(chat_id, type, path, options) |
| 150 | +====================================== |
| 151 | + |
| 152 | +* ``chat_id`` <String>|<Chat>|<User> |
| 153 | +* ``type`` <String> Must be one of the following: ``photo``, ``audio``, ``sticker``, ``document``, ``video``, ``voice`` |
| 154 | +* ``path`` <String> File's path for local files or file's id for uploaded files |
| 155 | +* ``options`` <Object> *Optional* |
| 156 | + |
| 157 | +Sends the specified file to the specified chat and returns a promise that resolves to a :doc:`Message` object representing |
| 158 | +what has been sent. |
| 159 | + |
| 160 | +===================== |
| 161 | +downloadFile(file_id) |
| 162 | +===================== |
| 163 | + |
| 164 | +* ``file_id`` <String>|<File> |
| 165 | + |
| 166 | +Returns a promise that resolves to a NodeJS `Buffer <https://nodejs.org/api/buffer.html>`_. |
| 167 | + |
| 168 | +==================================================== |
| 169 | +answerInlineQuery(inline_query_id, results, options) |
| 170 | +==================================================== |
| 171 | + |
| 172 | +* ``inline_query_id`` <String> |
| 173 | +* ``results`` <Array> Array of InlineQueryResult |
| 174 | +* ``options`` <Object> *Optional* |
| 175 | + |
| 176 | +Answers an inline query with the specified results and returns a promise that resolves to the response (according to |
| 177 | +Telegram, true on success). |
| 178 | + |
| 179 | +====================================================== |
| 180 | +editMessageText = (id, text, inline, options, chat_id) |
| 181 | +====================================================== |
| 182 | + |
| 183 | +* ``id`` <String> |
| 184 | +* ``text`` <String> |
| 185 | +* ``inline`` <Boolean> Is the message an inline one? |
| 186 | +* ``options`` <Object> *Optional* |
| 187 | +* ``chat_id`` <String>|<Chat>|<User> |
| 188 | + |
| 189 | +Updates the the specified message in the specified chat and returns a promise that resolves to a :doc:`Message` object |
| 190 | +representing the updated message. True is returned by the promise if the message is an inline one. |
| 191 | + |
| 192 | +============================================================ |
| 193 | +editMessageCaption = (id, caption, inline, options, chat_id) |
| 194 | +============================================================ |
| 195 | + |
| 196 | +* ``id`` <String> |
| 197 | +* ``caption`` <String> |
| 198 | +* ``inline`` <Boolean> Is the message an inline one? |
| 199 | +* ``options`` <Object> *Optional* |
| 200 | +* ``chat_id`` <String>|<Chat>|<User> |
| 201 | + |
| 202 | +Updates the the specified message caption in the specified chat and returns a promise that resolves to a :doc:`Message` |
| 203 | +object representing the updated message. True is returned by the promise if the message is an inline one. |
| 204 | + |
| 205 | +=============================================================== |
| 206 | +editMessageReplyMarkup = (id, markup, inline, options, chat_id) |
| 207 | +=============================================================== |
| 208 | + |
| 209 | +* ``id`` <String> |
| 210 | +* ``markup`` <Keyboard> |
| 211 | +* ``inline`` <Boolean> Is the message an inline one? |
| 212 | +* ``options`` <Object> *Optional* |
| 213 | +* ``chat_id`` <String>|<Chat>|<User> |
| 214 | + |
| 215 | +Updates the the specified message markup in the specified chat and returns a promise that resolves to a :doc:`Message` |
| 216 | +object representing the updated message. True is returned by the promise if the message is an inline one. |
| 217 | + |
| 218 | +=============================== |
| 219 | +getChatAdministrators (chat_id) |
| 220 | +=============================== |
| 221 | + |
| 222 | +* ``chat_id`` <String>|<Chat> |
| 223 | + |
| 224 | +Returns a promise that resolves to an array of :doc:`ChatMember` objects. |
| 225 | + |
| 226 | +=============================== |
| 227 | +getChatMember(chat_id, user_id) |
| 228 | +=============================== |
| 229 | + |
| 230 | +* ``chat_id`` <String>|<Chat>|<User> |
| 231 | +* ``user_id`` <String>|<User> |
| 232 | + |
| 233 | +Returns a promise that resolves to a :doc:`ChatMember` object. |
| 234 | + |
| 235 | +================================ |
| 236 | +kickChatMember(chat_id, user_id) |
| 237 | +================================ |
| 238 | + |
| 239 | +* ``chat_id`` <String>|<Chat> |
| 240 | +* ``user_id`` <String>|<User> |
| 241 | + |
| 242 | +Kicks the specified user from the specified chat and returns a promise that resolves to the response (according to |
| 243 | +Telegram, true on success). |
| 244 | + |
| 245 | +================================= |
| 246 | +unbanChatMember(chat_id, user_id) |
| 247 | +================================= |
| 248 | + |
| 249 | +* ``chat_id`` <String>|<Chat> |
| 250 | +* ``user_id`` <String>|<User> |
| 251 | + |
| 252 | +Unbans the specified user from the specified chat and returns a promise that resolves to the response (according to |
| 253 | +Telegram, true on success). |
| 254 | + |
| 255 | +============================ |
| 256 | +getChatMembersCount(chat_id) |
| 257 | +============================ |
| 258 | + |
| 259 | +* ``chat_id`` <String>|<Chat> |
| 260 | + |
| 261 | +Returns a promise that resolves to the response. |
| 262 | + |
| 263 | +=============================== |
| 264 | +sendChatAction(chat_id, action) |
| 265 | +=============================== |
| 266 | + |
| 267 | +* ``chat_id`` <String>|<Chat>|<User> |
| 268 | +* ``action`` <String> Must be one of the following: ``typing``, ``upload_photo``, ``record_video``, ``upload_video``, ``record_audio``, ``upload_audio``, ``upload_document``, ``find_location`` |
| 269 | + |
| 270 | +Returns a promise that resolves to the response (true on success). |
| 271 | + |
| 272 | + |
0 commit comments