node-telegram-bots-api 0.0.1-security → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of node-telegram-bots-api might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,5 +1,130 @@
1
- # Security holding package
1
+ <h1 align="center">Node.js Telegram Bot API</h1>
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ <div align="center">
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=node-telegram-bots-api for more information.
5
+ Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api).
6
+
7
+
8
+ [![Bot API](https://img.shields.io/badge/Bot%20API-v.6.8-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
9
+ [![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api)
10
+ [![Build Status](https://img.shields.io/travis/yagop/node-telegram-bot-api/master?style=flat-square&logo=travis)](https://travis-ci.org/yagop/node-telegram-bot-api)
11
+ [![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api)
12
+
13
+ [![https://telegram.me/node_telegram_bot_api](https://img.shields.io/badge/💬%20Telegram-Channel-blue.svg?style=flat-square)](https://telegram.me/node_telegram_bot_api)
14
+ [![https://t.me/+nc3A9Hs1S81mYzdk](https://img.shields.io/badge/💬%20Telegram-Group-blue.svg?style=flat-square)](https://t.me/+nc3A9Hs1S81mYzdk)
15
+ [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬%20Telegram-Yago_Perez-blue.svg?style=flat-square)](https://telegram.me/Yago_Perez)
16
+
17
+ </div>
18
+
19
+ ## 📦 Install
20
+
21
+ ```sh
22
+ npm i node-telegram-bot-api
23
+ ```
24
+
25
+ <br/>
26
+
27
+ > ✍️ **Note:** If you use Typescript you can install this package that contains type definitions for this library
28
+ >```sh
29
+ >npm install --save-dev @types/node-telegram-bot-api
30
+ >```
31
+
32
+ ## 🚀 Usage
33
+
34
+ ```js
35
+ const TelegramBot = require('node-telegram-bot-api');
36
+
37
+ // replace the value below with the Telegram token you receive from @BotFather
38
+ const token = 'YOUR_TELEGRAM_BOT_TOKEN';
39
+
40
+ // Create a bot that uses 'polling' to fetch new updates
41
+ const bot = new TelegramBot(token, {polling: true});
42
+
43
+ // Matches "/echo [whatever]"
44
+ bot.onText(/\/echo (.+)/, (msg, match) => {
45
+ // 'msg' is the received Message from Telegram
46
+ // 'match' is the result of executing the regexp above on the text content
47
+ // of the message
48
+
49
+ const chatId = msg.chat.id;
50
+ const resp = match[1]; // the captured "whatever"
51
+
52
+ // send back the matched "whatever" to the chat
53
+ bot.sendMessage(chatId, resp);
54
+ });
55
+
56
+ // Listen for any kind of message. There are different kinds of
57
+ // messages.
58
+ bot.on('message', (msg) => {
59
+ const chatId = msg.chat.id;
60
+
61
+ // send a message to the chat acknowledging receipt of their message
62
+ bot.sendMessage(chatId, 'Received your message');
63
+ });
64
+ ```
65
+
66
+ ## 📚 Documentation
67
+
68
+ * [Usage][usage]
69
+ * [Examples][examples]
70
+ * [Tutorials][tutorials]
71
+ * [Help Information][help]
72
+ * API Reference: ([api-release](../master/doc/api.md) / [development][api-dev] / [experimental][api-experimental])
73
+ * [Contributing to the Project][contributing]
74
+ * [Experimental Features][experimental]
75
+
76
+ _**Note**: Development is done against the **development** branch.
77
+ Code for the latest release resides on the **master** branch.
78
+ Experimental features reside on the **experimental** branch._
79
+
80
+
81
+ ## 💭 Community
82
+
83
+ We thank all the developers in the Open-Source community who continuously
84
+ take their time and effort in advancing this project.
85
+ See our [list of contributors][contributors].
86
+
87
+ We have a [Telegram channel][tg-channel] where we post updates on
88
+ the Project. Head over and subscribe!
89
+
90
+ We also have a [Telegram group][tg-group] to discuss issues related to this library.
91
+
92
+ Some things built using this library that might interest you:
93
+
94
+ * [tgfancy](https://github.com/GochoMugo/tgfancy): A fancy, higher-level wrapper for Telegram Bot API
95
+ * [node-telegram-bot-api-middleware](https://github.com/idchlife/node-telegram-bot-api-middleware): Middleware for node-telegram-bot-api
96
+ * [teleirc](https://github.com/FruitieX/teleirc): A simple Telegram ↔ IRC gateway
97
+ * [bot-brother](https://github.com/SerjoPepper/bot-brother): Node.js library to help you easily create telegram bots
98
+ * [redbot](https://github.com/guidone/node-red-contrib-chatbot): A Node-RED plugin to create telegram bots visually
99
+ * [node-telegram-keyboard-wrapper](https://github.com/alexandercerutti/node-telegram-keyboard-wrapper): A wrapper to improve keyboards structures creation through a more easy-to-see way (supports Inline Keyboards, Reply Keyboard, Remove Keyboard and Force Reply)
100
+ * [beetube-bot](https://github.com/kodjunkie/beetube-bot): A telegram bot for music, videos, movies, EDM tracks, torrent downloads, files and more.
101
+ * [telegram-inline-calendar](https://github.com/VDS13/telegram-inline-calendar): Date and time picker and inline calendar for Node.js telegram bots.
102
+ * [telegram-captcha](https://github.com/VDS13/telegram-captcha): Telegram bot to protect Telegram groups from automatic bots.
103
+
104
+
105
+ ## 👥 Contributors
106
+
107
+ <p align="center">
108
+ <a href="https://github.com/yagop/node-telegram-bot-api/graphs/contributors">
109
+ <img src="https://contrib.rocks/image?repo=yagop/node-telegram-bot-api" />
110
+ </a>
111
+ </p>
112
+
113
+ ## License
114
+
115
+ **The MIT License (MIT)**
116
+
117
+ Copyright © 2019 Yago
118
+
119
+ [usage]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/usage.md
120
+ [examples]:https://github.com/yagop/node-telegram-bot-api/tree/master/examples
121
+ [help]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/help.md
122
+ [tutorials]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/tutorials.md
123
+ [api-dev]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/api.md
124
+ [api-release]:https://github.com/yagop/node-telegram-bot-api/tree/release/doc/api.md
125
+ [api-experimental]:https://github.com/yagop/node-telegram-bot-api/tree/experimental/doc/api.md
126
+ [contributing]:https://github.com/yagop/node-telegram-bot-api/tree/master/CONTRIBUTING.md
127
+ [contributors]:https://github.com/yagop/node-telegram-bot-api/graphs/contributors
128
+ [experimental]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/experimental.md
129
+ [tg-channel]:https://telegram.me/node_telegram_bot_api
130
+ [tg-group]:https://t.me/+nc3A9Hs1S81mYzdk
package/doc/api.hbs ADDED
@@ -0,0 +1,19 @@
1
+ # API Reference
2
+
3
+ **Note:** If you are looking for available [events](usage.md#events) or usage of api, please refer [`usage.md`](usage.md).
4
+
5
+ {{#class name="TelegramBot"~}}
6
+ {{>header~}}
7
+ {{>body~}}
8
+ {{>member-index~}}
9
+ {{>members~}}
10
+ {{/class}}
11
+ * * *
12
+
13
+
14
+ [usage-sending-files-performance]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/usage.md#sending-files-performance
15
+ [setWebHook-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#telegrambotsetwebhookurl-cert
16
+ [getUpdates-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUpdates
17
+ [getUserProfilePhotos-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUserProfilePhotos
18
+ [answerCallbackQuery-v0.27.1]:https://github.com/yagop/node-telegram-bot-api/blob/v0.27.1/doc/api.md#TelegramBot+answerCallbackQuery
19
+ [answerCallbackQuery-v0.29.0]:https://github.com/yagop/node-telegram-bot-api/blob/v0.29.0/doc/api.md#TelegramBot+answerCallbackQuery
package/doc/api.md ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ # Experimental
2
+
3
+ Experimental features are things we are trying out. We are **not** sure
4
+ if they'll become stable and move into the `master` branch.
5
+ Try them out and give feedback to support stabilizing them.
6
+
7
+ * [Features](#features)
8
+ * [API Reference][api-experimental]
9
+ * [Installation](#installation)
10
+
11
+
12
+ <a name="features"></a>
13
+ ## features:
14
+
15
+ * Support API method `deleteMessage`
16
+
17
+ Open issues tagged `experimental`: [link](https://github.com/yagop/node-telegram-bot-api/issues?q=is%3Apr+is%3Aopen+label%3Aexperimental)
18
+
19
+
20
+ <a name="installation"></a>
21
+ ## installation:
22
+
23
+ ```bash
24
+ $ npm install yagop/node-telegram-bot-api#experimental
25
+ ```
26
+
27
+
28
+ [api-experimental]:https://github.com/yagop/node-telegram-bot-api/tree/experimental/doc/api.md
package/doc/help.md ADDED
@@ -0,0 +1,151 @@
1
+ # Help Information
2
+
3
+ * [Common Pitfalls](#pitfalls)
4
+ * [FAQs](#faqs)
5
+
6
+ <a name="pitfalls"></a>
7
+ ## Common Pitfalls
8
+
9
+ <a name="reply-to-message"></a>
10
+ ### Failing to receive reply with `ReplyToMessage`
11
+
12
+ The user has to **manually reply** to your message, by tapping on the bot's message and select *Reply*.
13
+
14
+ Sources:
15
+
16
+ * Issue [#113](https://github.com/yagop/node-telegram-bot-api/issues/113)
17
+
18
+ <a name="faqs"></a>
19
+ ## Frequently Asked Questions
20
+
21
+ > Check out [all questions ever asked][questions] on our Github Issues.
22
+
23
+ 1. [How do I send GIFs?](#gifs)
24
+ 1. [Why and When do I need a certificate when using WebHooks?](#webhook-cert)
25
+ 1. [How do I know when a user leaves a chat?](#leave-chat)
26
+ 1. [What does this error mean?](#error-meanings)
27
+ 1. [How do I know the selected option in reply keyboard?](#reply-keyboard)
28
+ 1. [How do I send multiple message in correct sequence?](#ordered-sending)
29
+ 1. [How do I run my bot behind a proxy?](#proxy)
30
+ 1. [Can you add feature X to the library?](#new-feature)
31
+ 1. [Is this scalable?](#scalable)
32
+ 1. [How do I listen for messages in a chat group?](#messages-in-chat)
33
+ 1. [How do I know when a user blocks the bot?](#blocked-bot)
34
+
35
+ <a name="gifs"></a>
36
+ ### How do I send GIFs?
37
+
38
+ You might be trying to send your animated GIFs using *TelegramBot#sendPhoto()*.
39
+ The method mostly supports static images. As noted by the community,
40
+ it seems you need to send them as documents, using *TelegramBot#sendDocument()*.
41
+
42
+ ```js
43
+ bot.sendDocument(chatId, 'cat.gif');
44
+ ```
45
+
46
+ Sources:
47
+
48
+ * Issue [#11](https://github.com/yagop/node-telegram-bot-api/issues/11)
49
+
50
+ <a name="webhook-cert"></a>
51
+ ### Why and When do I need a certificate when using WebHooks?
52
+
53
+ *Not done. PRs welcome!*
54
+
55
+ Sources:
56
+
57
+ * Issue [#63](https://github.com/yagop/node-telegram-bot-api/issues/63)
58
+ * Issue [#125](https://github.com/yagop/node-telegram-bot-api/issues/125)
59
+
60
+ <a name="leave-chat"></a>
61
+ ### How do I know when a user leaves a chat?
62
+
63
+ *Not done. PRs welcome!*
64
+
65
+ Sources:
66
+
67
+ * Issue [#248](https://github.com/yagop/node-telegram-bot-api/issues/248)
68
+
69
+ <a name="error-meanings"></a>
70
+ ### What does this error mean?
71
+
72
+ * [502 Bad Gateway](https://github.com/yagop/node-telegram-bot-api/issues/377)
73
+
74
+ *Not complete. PRs welcome!*
75
+
76
+ Sources:
77
+
78
+ * Issue [#73](https://github.com/yagop/node-telegram-bot-api/issues/73)
79
+ * Issue [#99](https://github.com/yagop/node-telegram-bot-api/issues/99)
80
+ * Issue [#101](https://github.com/yagop/node-telegram-bot-api/issues/101)
81
+ * Issue [#107](https://github.com/yagop/node-telegram-bot-api/issues/107)
82
+ * Issue [#156](https://github.com/yagop/node-telegram-bot-api/issues/156)
83
+ * Issue [#170](https://github.com/yagop/node-telegram-bot-api/issues/170)
84
+ * Issue [#244](https://github.com/yagop/node-telegram-bot-api/issues/244)
85
+
86
+ <a name="reply-keyboard"></a>
87
+ ### How do I know the selected option in reply keyboard?
88
+
89
+ *Not done. PRs welcome!*
90
+
91
+ Sources:
92
+
93
+ * Issue [#108](https://github.com/yagop/node-telegram-bot-api/issues/108)
94
+
95
+ <a name="ordered-sending"></a>
96
+ ### How do I send multiple message in correct sequence?
97
+
98
+ *Not done. PRs welcome!*
99
+
100
+ Sources:
101
+
102
+ * Issue [#240](https://github.com/yagop/node-telegram-bot-api/issues/240)
103
+
104
+ <a name="proxy"></a>
105
+ ### How do I run my bot behind a proxy?
106
+
107
+ *Not done. PRs welcome!*
108
+
109
+ Sources:
110
+
111
+ * Issue [#122](https://github.com/yagop/node-telegram-bot-api/issues/122)
112
+ * Issue [#253](https://github.com/yagop/node-telegram-bot-api/issues/253)
113
+ * Issue [#766](https://github.com/yagop/node-telegram-bot-api/issues/766)
114
+
115
+ <a name="new-feature"></a>
116
+ ### Can you add feature X to the library?
117
+
118
+ *Not done. PRs welcome!*
119
+
120
+ Sources:
121
+
122
+ * Issue [#238](https://github.com/yagop/node-telegram-bot-api/issues/238)
123
+
124
+ <a name="scalable"></a>
125
+ ### Is this scalable?
126
+
127
+ *Not done. PRs welcome!*
128
+
129
+ Sources:
130
+
131
+ * Issue [#219](https://github.com/yagop/node-telegram-bot-api/issues/219)
132
+
133
+ <a name="messages-in-chat"></a>
134
+ ### How do I listen for messages in a chat group?
135
+
136
+ *Not done. PRs welcome!*
137
+
138
+ Sources:
139
+
140
+ * Issue [#304](https://github.com/yagop/node-telegram-bot-api/issues/304)
141
+
142
+ <a name="blocked-bot"></a>
143
+ ### How do I know when a user blocks the bot?
144
+
145
+ *Not done. PRs welcome!*
146
+
147
+ Sources:
148
+
149
+ * Issue [#273](https://github.com/yagop/node-telegram-bot-api/issues/273)
150
+
151
+ [questions]:https://github.com/yagop/node-telegram-bot-api/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Aquestion%20
@@ -0,0 +1,12 @@
1
+ # Tutorials
2
+
3
+ * [node-telegram-bot-api-tutorial by @hosein2398](https://github.com/hosein2398/node-telegram-bot-api-tutorial)
4
+ * [node-telegram-bot-api-persian-language by @saeedhei](https://github.com/saeedhei/node-telegram-bot-api-persian-language)
5
+ * [Node.JS: Делаем своего Telegram бота [RUS]](https://archakov.im/post/telegram-bot-on-nodejs)
6
+ * [YouTube: Пишем Telegram бота на NodeJS [RUS]](https://www.youtube.com/watch?v=RS1nmDMf69U&list=PL6AOr-PZtK-mM2QC1ixyfa5CtJZGK61aN)
7
+ * [Node.jsでTelegramのチャットボットを作る - Qiita](https://qiita.com/neetshin/items/0e2f6fa3ade41adb77bc)
8
+ * [Guía: Creación de bots de Telegram en Nodejs [ES]](https://tecnonucleous.com/creacion-de-bots-de-telegram-en-nodejs/)
9
+ * [node-telegram-bot-api-tutorial:a telegram bot helper to send templates by sms](https://github.com/vito2005/chatManagerTelegramBot)
10
+ * [Telegram bot using blockchain services](https://ilanolkies.com/post/Telegram-bot-using-blockchain-services)
11
+ * [How to set webhooks using express local server and NGROK](https://github.com/leobloise/node-telegram-bot-api-wb-tutorial)
12
+ > Send a PR with useful links **not** listed above
package/doc/usage.md ADDED
@@ -0,0 +1,269 @@
1
+ # Usage
2
+
3
+ - [Usage](#usage)
4
+ - [Events](#events)
5
+ - [WebHooks](#webhooks)
6
+ - [Sending files](#sending-files)
7
+ - [File Options (metadata)](#file-options-metadata)
8
+ - [Performance Issue](#performance-issue)
9
+ - [Error handling](#error-handling)
10
+ - [Polling errors](#polling-errors)
11
+ - [WebHook errors](#webhook-errors)
12
+
13
+ <a name="events"></a>
14
+ ## Events
15
+
16
+ *TelegramBot* is an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
17
+ that emits the following events:
18
+
19
+ 1. `message`: Received a new incoming [Message][message] of any kind
20
+ 1. Depending on the properties of the [Message][message], one of these
21
+ events may **ALSO** be emitted: `text`, `audio`, `document`, `photo`,
22
+ `sticker`, `video`, `voice`, `contact`, `location`,
23
+ `new_chat_members`, `left_chat_member`, `new_chat_title`,
24
+ `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
25
+ `game`, `pinned_message`, `poll`, `dice`, `migrate_from_chat_id`, `migrate_to_chat_id`,
26
+ `channel_chat_created`, `supergroup_chat_created`,
27
+ `successful_payment`, `invoice`, `video_note`
28
+ 1. **Arguments**: `message` ([Message][message]), `metadata` (`{ type?:string }`)
29
+ 1. `new_chat_participant`, `left_chat_participant` are **deprecated**
30
+ 1. `callback_query`: Received a new incoming [Callback Query][callback-query]
31
+ 1. `inline_query`: Received a new incoming [Inline Query][inline-query]
32
+ 1. `chosen_inline_result`: Received result of an inline query i.e. [ChosenInlineResult][chosen-inline-result]
33
+ 1. `channel_post`: Received a new incoming channel post of any kind
34
+ 1. `edited_message`: Received a new version of a message that is known to the bot and was edited
35
+ 1. `edited_message_text`
36
+ 1. `edited_message_caption`
37
+ 1. `edited_channel_post`: Received a new version of a channel post that is known to the bot and was edited
38
+ 1. `edited_channel_post_text`
39
+ 1. `edited_channel_post_caption`
40
+ 1. `shipping_query`: Received a new incoming shipping query
41
+ 1. `pre_checkout_query`: Received a new incoming pre-checkout query
42
+ 1. `poll`: Received a new incoming poll
43
+ 2. `poll_answer`: A user has changed their answer in a non-anonymous poll (Only polls sent by the bot)
44
+ 3. `chat_member`: A chat member's status was updated in a chat
45
+ 4. `my_chat_member`: The bot's chat member status was updated in a chat
46
+ 5. `chat_join_request`: A request to join the chat has been sent (The bot must have the can_invite_users administrator right)
47
+ 5. `polling_error`: Error occurred during polling. See [polling errors](#polling-errors).
48
+ 6. `webhook_error`: Error occurred handling a webhook request. See [webhook errors](#webhook-errors).
49
+ 7. `error`: Unexpected error occurred, usually fatal!
50
+
51
+ **Tip:** Its much better to listen a specific event rather than on
52
+ `message` in order to stay safe from the content.
53
+
54
+ **Tip:** Bot must be enabled on [inline mode][inline-mode] for receive some
55
+ messages.
56
+
57
+ <a name="webhooks"></a>
58
+ ## WebHooks
59
+
60
+ Telegram only supports HTTPS connections to WebHooks.
61
+ Therefore, in order to set a WebHook, you will need a SSL certificate.
62
+ Since August 29, 2015 Telegram supports self-signed ones, thus, you can
63
+ generate them:
64
+
65
+ ```bash
66
+ # Our private cert will be key.pem, keep this file private
67
+ $ openssl genrsa -out key.pem 2048
68
+
69
+ # Our public certificate will be crt.pem
70
+ $ openssl req -new -sha256 -key key.pem -out crt.pem
71
+ ```
72
+
73
+ Once they are generated, the `crt.pem` should be uploaded, when setting up
74
+ your webhook. For example,
75
+
76
+ ```js
77
+ bot.setWebHook('public-url.com', {
78
+ certificate: 'path/to/crt.pem', // Path to your crt.pem
79
+ });
80
+ ```
81
+
82
+ **Note:** If you encounter an error, like
83
+ `Error: error:0906D06C:PEM routines:PEM_read_bio:no start line`,
84
+ you may want to proceed to [this issue][issue-63] for more information.
85
+
86
+ <a name="sending-files"></a>
87
+ ## Sending files
88
+
89
+ The library makes it easy to get started sending files. *By default*, you
90
+ may provide a **file-path** and the library will handle reading it for you.
91
+ For example,
92
+
93
+ ```js
94
+ bot.sendAudio(chatId, 'path/to/audio.mp3');
95
+ ```
96
+
97
+ You may also pass in a **Readable Stream** from which data will be piped.
98
+ For example,
99
+
100
+ ```js
101
+ const stream = fs.createReadStream('path/to/audio.mp3');
102
+ bot.sendAudio(chatId, stream);
103
+ ```
104
+
105
+ You may also pass in a **Buffer** containing the contents of your file.
106
+ For example,
107
+
108
+ ```js
109
+ const buffer = fs.readFileSync('path/to/audio.mp3'); // sync! that's sad! :-( Just making a point!
110
+ bot.sendAudio(chatId, buffer);
111
+ ```
112
+
113
+ If you already have a **File ID**, you earlier retrieved from Telegram,
114
+ you may pass it in, for example:
115
+
116
+ ```js
117
+ const fileId = getFileIdSomehow();
118
+ bot.sendAudio(chatId, fileId);
119
+ ```
120
+
121
+ Some API methods, such as *SendPhoto*, allow passing a **HTTP URL**, that
122
+ the Telegram servers will use to download the file. For example,
123
+
124
+ ```js
125
+ const url = 'https://telegram.org/img/t_logo.png';
126
+ bot.sendPhoto(chatId, url);
127
+ ```
128
+
129
+ If you wish to explicitly specify the filename or
130
+ [MIME type](http://en.wikipedia.org/wiki/Internet_media_type),
131
+ you may pass an additional argument as file options, like so:
132
+
133
+ ```js
134
+ const fileOptions = {
135
+ // Explicitly specify the file name.
136
+ filename: 'customfilename',
137
+ // Explicitly specify the MIME type.
138
+ contentType: 'audio/mpeg',
139
+ };
140
+ bot.sendAudio(chatId, data, {}, fileOptions);
141
+ ```
142
+
143
+ **NOTE:** You **MUST** provide an empty object (`{}`) in place of
144
+ *Additional Telegram query options*, if you have **no** query options
145
+ to specify. For example,
146
+
147
+ ```js
148
+ // WRONG!
149
+ // 'fileOptions' will be taken as additional Telegram query options!!!
150
+ bot.sendAudio(chatId, data, fileOptions);
151
+
152
+ // RIGHT!
153
+ bot.sendAudio(chatId, data, {}, fileOptions);
154
+ ```
155
+
156
+
157
+ <a name="sending-files-options"></a>
158
+ ### File Options (metadata)
159
+
160
+ When sending files, the library automatically resolves
161
+ the `filename` and `contentType` properties.
162
+ **For now, this has to be manually activated using environment
163
+ variable `NTBA_FIX_350`.**
164
+
165
+ In order of highest-to-lowest precedence in searching for
166
+ a value, when resolving the `filename`:
167
+
168
+ *(`fileOptions` is the Object argument passed to the method.
169
+ The "file" argument passed to the method can be a `Stream`,
170
+ `Buffer` or `filepath`.)*
171
+
172
+ 1. Is `fileOptions.filename` explictly defined?
173
+ 1. Does `Stream#path` exist?
174
+ 1. Is `filepath` provided?
175
+ 1. Default to `"filename"`
176
+
177
+ And the `contentType`:
178
+
179
+ 1. Is `fileOptions.contentType` explictly-defined?
180
+ 1. Does `Stream#path` exist?
181
+ 1. Try detecting file-type from the `Buffer`
182
+ 1. Is `filepath` provided?
183
+ 1. Is `fileOptions.filename` explicitly defined?
184
+ 1. Default to `"application/octet-stream"`
185
+
186
+ <a name="sending-files-performance"></a>
187
+ ### Performance Issue
188
+
189
+ To support providing file-paths to methods that send files involves
190
+ performing a file operation, i.e. *fs.existsSync()*, that checks for
191
+ the existence of the file at the provided path. While the cost of
192
+ this operation *might* be negligible in most use cases, if you want
193
+ to squeeze the best performance out of this library, you may wish to
194
+ disable this behavior.
195
+
196
+ This will mean that you will **NOT** be able to pass in file-paths.
197
+ You will have to use Streams or Buffers to provide the file contents.
198
+
199
+ Disabling this behavior:
200
+
201
+ ```js
202
+ const bot = new TelegramBot(token, {
203
+ filepath: false,
204
+ });
205
+ ```
206
+
207
+ <a name="error-handling"></a>
208
+ ## Error handling
209
+
210
+ Every `Error` object we pass back has the properties:
211
+
212
+ * `code` (String):
213
+ * value is `EFATAL` if error was fatal e.g. network error
214
+ * value is `EPARSE` if response body could **not** be parsed
215
+ * value is `ETELEGRAM` if error was returned from Telegram servers
216
+ * `response` ([http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)):
217
+ * available if `error.code` is **not** `EFATAL`
218
+ * `response.body` (String|Object): Error response from Telegram
219
+ * type is `String` if `error.code` is `EPARSE`
220
+ * type is `Object` if `error.code` is `ETELEGRAM`
221
+
222
+ For example, sending message to a non-existent user:
223
+
224
+ ```js
225
+ bot.sendMessage(nonExistentUserId, 'text').catch((error) => {
226
+ console.log(error.code); // => 'ETELEGRAM'
227
+ console.log(error.response.body); // => { ok: false, error_code: 400, description: 'Bad Request: chat not found' }
228
+ });
229
+ ```
230
+
231
+ <a name="polling-errors"></a>
232
+ ## Polling errors
233
+
234
+ An error may occur during polling. It is up to you to handle it
235
+ as you see fit. You may decide to crash your bot after a maximum number
236
+ of polling errors occurring. **It is all up to you.**
237
+
238
+ By default, the polling error is just logged to stderr, if you do
239
+ **not** handle this event yourself.
240
+
241
+ Listen on the `'polling_error'` event. For example,
242
+
243
+ ```js
244
+ bot.on('polling_error', (error) => {
245
+ console.log(error.code); // => 'EFATAL'
246
+ });
247
+ ```
248
+
249
+ <a name="webhook-errors"></a>
250
+ ## WebHook errors
251
+
252
+ Just like with [polling errors](#polling-errors), you decide on how to
253
+ handle it. By default, the error is logged to stderr.
254
+
255
+ Listen on the `'webhook_error'` event. For example,
256
+
257
+ ```js
258
+ bot.on('webhook_error', (error) => {
259
+ console.log(error.code); // => 'EPARSE'
260
+ });
261
+ ```
262
+
263
+ [update]:https://core.telegram.org/bots/api#update
264
+ [message]:https://core.telegram.org/bots/api#message
265
+ [callback-query]:https://core.telegram.org/bots/api#callbackquery
266
+ [inline-query]:https://core.telegram.org/bots/api#inlinequery
267
+ [chosen-inline-result]:https://core.telegram.org/bots/api#choseninlineresult
268
+ [inline-mode]:https://core.telegram.org/bots/api#inline-mode
269
+ [issue-63]:https://github.com/yagop/node-telegram-bot-api/issues/63
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * If running on Nodejs 5.x and below, we load the transpiled code.
3
+ * Otherwise, we use the ES6 code.
4
+ * We are deprecating support for Node.js v5.x and below.
5
+ */
6
+ const majorVersion = parseInt(process.versions.node.split('.')[0], 10);
7
+ if (majorVersion <= 5) {
8
+ const deprecate = require('./src/utils').deprecate;
9
+ deprecate('Node.js v5.x and below will no longer be supported in the future');
10
+ module.exports = require('./lib/telegram');
11
+ } else {
12
+ module.exports = require('./src/telegram');
13
+ }