@zero-bot.net/tg-bot-api 1.0.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.
- package/.github/ISSUE_TEMPLATE.md +68 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +23 -0
- package/CHANGELOG.md +515 -0
- package/CODE_OF_CONDUCT.md +74 -0
- package/CONTRIBUTING.md +45 -0
- package/LICENSE.md +22 -0
- package/README.md +130 -0
- package/doc/api.hbs +19 -0
- package/doc/api.md +2470 -0
- package/doc/experimental.md +28 -0
- package/doc/help.md +151 -0
- package/doc/tutorials.md +12 -0
- package/doc/usage.md +269 -0
- package/index.js +13 -0
- package/lib/errors.js +62 -0
- package/lib/telegram.js +3057 -0
- package/lib/telegramPolling.js +196 -0
- package/lib/telegramWebHook.js +156 -0
- package/lib/utils.js +3 -0
- package/package.json +73 -0
- package/src/errors.js +65 -0
- package/src/telegram.js +3119 -0
- package/src/telegramPolling.js +202 -0
- package/src/telegramWebHook.js +158 -0
- package/src/utils.js +3 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
> If you are willing to contribute, first you should know that
|
|
4
|
+
> I will love you and so will the Telegram Bot community.
|
|
5
|
+
|
|
6
|
+
Before proceeding any further, read the following documents:
|
|
7
|
+
|
|
8
|
+
1. [Code of Conduct][coc]
|
|
9
|
+
1. [License][license]
|
|
10
|
+
|
|
11
|
+
## General Information
|
|
12
|
+
|
|
13
|
+
### Creating a Github issue:
|
|
14
|
+
|
|
15
|
+
1. Ensure that your issue does **not** already exist. [Do a search](https://github.com/ZeroBot-net/tg-bot-api/issues).
|
|
16
|
+
2. Browse through [StackOverflow](https://stackoverflow.com/search?q=telegram+nodejs) and other similar platforms.
|
|
17
|
+
3. Should you open your issue, ensure you use the English language for
|
|
18
|
+
the wider target audience.
|
|
19
|
+
4. Be patient please.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Updating API Reference i.e. generating `doc/api.md`
|
|
23
|
+
|
|
24
|
+
Run:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ npm run doc
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Running tests
|
|
32
|
+
|
|
33
|
+
Please read `test/README.md` for more information.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Transpiling ES2015 for older Node.js versions
|
|
37
|
+
|
|
38
|
+
We use babel to transpile the code:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ npm run build
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
[coc]:https://github.com/ZeroBot-net/tg-bot-api/blob/master/CODE_OF_CONDUCT.md
|
|
45
|
+
[license]:https://github.com/ZeroBot-net/tg-bot-api/blob/master/LICENSE.md
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Yago
|
|
4
|
+
Copyright (c) 2016 GrandpaEJ
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<h1 align="center">Node.js Telegram Bot API</h1>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api).
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[](https://core.telegram.org/bots/api)
|
|
9
|
+
[](https://www.npmjs.org/package/@zero-bot.net/tg-bot-api)
|
|
10
|
+
[](https://travis-ci.org/ZeroBot-net/tg-bot-api)
|
|
11
|
+
[](https://codecov.io/gh/ZeroBot-net/tg-bot-api)
|
|
12
|
+
|
|
13
|
+
[](https://telegram.me/node_telegram_bot_api)
|
|
14
|
+
[](https://t.me/+nc3A9Hs1S81mYzdk)
|
|
15
|
+
[](https://telegram.me/Yago_Perez)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## 📦 Install
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm i @zero-bot.net/tg-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/@zero-bot.net/tg-bot-api
|
|
30
|
+
>```
|
|
31
|
+
|
|
32
|
+
## 🚀 Usage
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const TelegramBot = require('@zero-bot.net/tg-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
|
+
* [@zero-bot.net/tg-bot-api-middleware](https://github.com/idchlife/@zero-bot.net/tg-bot-api-middleware): Middleware for @zero-bot.net/tg-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/ZeroBot-net/tg-bot-api/graphs/contributors">
|
|
109
|
+
<img src="https://contrib.rocks/image?repo=ZeroBot-net/tg-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/ZeroBot-net/tg-bot-api/tree/master/doc/usage.md
|
|
120
|
+
[examples]:https://github.com/ZeroBot-net/tg-bot-api/tree/master/examples
|
|
121
|
+
[help]:https://github.com/ZeroBot-net/tg-bot-api/tree/master/doc/help.md
|
|
122
|
+
[tutorials]:https://github.com/ZeroBot-net/tg-bot-api/tree/master/doc/tutorials.md
|
|
123
|
+
[api-dev]:https://github.com/ZeroBot-net/tg-bot-api/tree/master/doc/api.md
|
|
124
|
+
[api-release]:https://github.com/ZeroBot-net/tg-bot-api/tree/release/doc/api.md
|
|
125
|
+
[api-experimental]:https://github.com/ZeroBot-net/tg-bot-api/tree/experimental/doc/api.md
|
|
126
|
+
[contributing]:https://github.com/ZeroBot-net/tg-bot-api/tree/master/CONTRIBUTING.md
|
|
127
|
+
[contributors]:https://github.com/ZeroBot-net/tg-bot-api/graphs/contributors
|
|
128
|
+
[experimental]:https://github.com/ZeroBot-net/tg-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/ZeroBot-net/tg-bot-api/tree/master/doc/usage.md#sending-files-performance
|
|
15
|
+
[setWebHook-v0.25.0]:https://github.com/ZeroBot-net/tg-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#telegrambotsetwebhookurl-cert
|
|
16
|
+
[getUpdates-v0.25.0]:https://github.com/ZeroBot-net/tg-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUpdates
|
|
17
|
+
[getUserProfilePhotos-v0.25.0]:https://github.com/ZeroBot-net/tg-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUserProfilePhotos
|
|
18
|
+
[answerCallbackQuery-v0.27.1]:https://github.com/ZeroBot-net/tg-bot-api/blob/v0.27.1/doc/api.md#TelegramBot+answerCallbackQuery
|
|
19
|
+
[answerCallbackQuery-v0.29.0]:https://github.com/ZeroBot-net/tg-bot-api/blob/v0.29.0/doc/api.md#TelegramBot+answerCallbackQuery
|