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 | [![Bot API](https://img.shields.io/badge/Bot%20API-v.5.5-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://telegram.me/ntbasupport](https://img.shields.io/badge/💬%20Telegram-Group-blue.svg?style=flat-square)](https://telegram.me/ntbasupport)
|
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 | ## Usage
|
26 |
|
27 | ```js
|
28 | const TelegramBot = require('node-telegram-bot-api');
|
29 |
|
30 | // replace the value below with the Telegram token you receive from @BotFather
|
31 | const token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
32 |
|
33 | // Create a bot that uses 'polling' to fetch new updates
|
34 | const bot = new TelegramBot(token, {polling: true});
|
35 |
|
36 | // Matches "/echo [whatever]"
|
37 | bot.onText(/\/echo (.+)/, (msg, match) => {
|
38 | // 'msg' is the received Message from Telegram
|
39 | // 'match' is the result of executing the regexp above on the text content
|
40 | // of the message
|
41 |
|
42 | const chatId = msg.chat.id;
|
43 | const resp = match[1]; // the captured "whatever"
|
44 |
|
45 | // send back the matched "whatever" to the chat
|
46 | bot.sendMessage(chatId, resp);
|
47 | });
|
48 |
|
49 | // Listen for any kind of message. There are different kinds of
|
50 | // messages.
|
51 | bot.on('message', (msg) => {
|
52 | const chatId = msg.chat.id;
|
53 |
|
54 | // send a message to the chat acknowledging receipt of their message
|
55 | bot.sendMessage(chatId, 'Received your message');
|
56 | });
|
57 | ```
|
58 |
|
59 | ## Documentation
|
60 |
|
61 | * [Usage][usage]
|
62 | * [Examples][examples]
|
63 | * [Tutorials][tutorials]
|
64 | * [Help Information][help]
|
65 | * API Reference [api-release] / [development][api-dev] / [experimental][api-experimental])
|
66 | * [Contributing to the Project][contributing]
|
67 | * [Experimental Features][experimental]
|
68 |
|
69 | _**Note**: Development is done against the **master** branch.
|
70 | Code for the latest release resides on the **release** branch.
|
71 | Experimental features reside on the **experimental** branch._
|
72 |
|
73 |
|
74 | ## Community
|
75 |
|
76 | We thank all the developers in the Open-Source community who continuously
|
77 | take their time and effort in advancing this project.
|
78 | See our [list of contributors][contributors].
|
79 |
|
80 | We have a [Telegram channel][tg-channel] where we post updates on
|
81 | the Project. Head over and subscribe!
|
82 |
|
83 | We also have a [Telegram group][tg-group] to discuss issues related to this library.
|
84 |
|
85 | Some things built using this library that might interest you:
|
86 |
|
87 | * [tgfancy](https://github.com/GochoMugo/tgfancy): A fancy, higher-level wrapper for Telegram Bot API
|
88 | * [node-telegram-bot-api-middleware](https://github.com/idchlife/node-telegram-bot-api-middleware): Middleware for node-telegram-bot-api
|
89 | * [teleirc](https://github.com/FruitieX/teleirc): A simple Telegram ↔ IRC gateway
|
90 | * [bot-brother](https://github.com/SerjoPepper/bot-brother): Node.js library to help you easily create telegram bots
|
91 | * [redbot](https://github.com/guidone/node-red-contrib-chatbot): A Node-RED plugin to create telegram bots visually
|
92 | * [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)
|
93 |
|
94 | ## License
|
95 |
|
96 | **The MIT License (MIT)**
|
97 |
|
98 | Copyright © 2019 Yago
|
99 |
|
100 | [usage]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/usage.md
|
101 | [examples]:https://github.com/yagop/node-telegram-bot-api/tree/master/examples
|
102 | [help]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/help.md
|
103 | [tutorials]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/tutorials.md
|
104 | [api-dev]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/api.md
|
105 | [api-release]:https://github.com/yagop/node-telegram-bot-api/tree/release/doc/api.md
|
106 | [api-experimental]:https://github.com/yagop/node-telegram-bot-api/tree/experimental/doc/api.md
|
107 | [contributing]:https://github.com/yagop/node-telegram-bot-api/tree/master/CONTRIBUTING.md
|
108 | [contributors]:https://github.com/yagop/node-telegram-bot-api/graphs/contributors
|
109 | [experimental]:https://github.com/yagop/node-telegram-bot-api/tree/master/doc/experimental.md
|
110 | [tg-channel]:https://telegram.me/node_telegram_bot_api
|
111 | [tg-group]:https://telegram.me/ntbasupport
|