Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

Commit 8c57568

Browse files
committed
Documentation for the Bot object
1 parent 4c65984 commit 8c57568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+16840
-1
lines changed
-270 Bytes
Binary file not shown.
21.9 KB
Binary file not shown.

docs/_build/doctrees/index.doctree

13.4 KB
Binary file not shown.
65.4 KB
Binary file not shown.
47 KB
Binary file not shown.

docs/_build/html/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 3b634d9e4d1985337b053f0cbb161bed
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/_build/html/.nojekyll

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Welcome to Nodeogram's documentation!
2+
=====================================
3+
4+
Nodeogram is a simple yet complete Node.JS module for Telegram bots.
5+
6+
========
7+
Features
8+
========
9+
10+
* **Not a wrapper**. Nodeogram takes the Telegram API to the next level and allows you to create your bots while handling all the boring stuff for you
11+
* **Complete**. Nodeogram features all of the most recent API updates and is designed not to block you from using right away the not yet implemented ones
12+
* **Promises**. The entire library is promise-based
13+
* **Event based**. Nodeogram provides an event-based handling of updates, allowing you to interact more easily with messages, commands, callback and inline queries.
14+
* Nodeogram is an open-source project available on `GitHub <https://github.com/ALCC01/nodeogram>`_ and `npm <https://www.npmjs.com/package/nodeogram>`_.
15+
16+
===============
17+
Getting started
18+
===============
19+
20+
First, you'll need to install the module
21+
22+
.. code-block:: bash
23+
24+
npm i --save nodeogram
25+
26+
Once the package is installed, you can start working on your bot.
27+
28+
.. code-block:: javascript
29+
30+
const nodeogram = require('nodeogram'),
31+
bot = new nodeogram.Bot('your-token-goes-here');
32+
33+
bot.init();
34+
bot.on('message', message => message.reply("Hello World!"));
35+
36+
And you are done. You can more extensive examples in the :doc:`quickstart`
37+
38+
=======
39+
License
40+
=======
41+
42+
Nodeogram is released under the GNU General Public License 3.0.
43+
44+
.. code-block:: none
45+
46+
Nodeogram - A Node.JS Telegram bots API library
47+
Copyright (C) 2016 Alberto Coscia <[email protected]>
48+
49+
This program is free software: you can redistribute it and/or modify
50+
it under the terms of the GNU General Public License as published by
51+
the Free Software Foundation, either version 3 of the License, or
52+
(at your option) any later version.
53+
54+
This program is distributed in the hope that it will be useful,
55+
but WITHOUT ANY WARRANTY; without even the implied warranty of
56+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57+
GNU General Public License for more details.
58+
59+
You should have received a copy of the GNU General Public License
60+
along with this program. If not, see <http://www.gnu.org/licenses/>.
61+
62+
.. _user-documentation:
63+
.. toctree::
64+
:maxdepth: 3
65+
:caption: User Documentation
66+
:glob:
67+
68+
quickstart
69+
70+
.. _objects-documentation:
71+
.. toctree::
72+
:maxdepth: 3
73+
:caption: Objects
74+
:glob:
75+
76+
objects/Bot
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
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

Comments
 (0)