node-telegram-api/README.md

53 lines
1.2 KiB
Markdown
Raw Normal View History

2015-06-26 17:20:54 +00:00
# Telegram Bots
Create and control [Telegram bots](https://core.telegram.org/bots) easily
using the new [Telegram API](https://core.telegram.org/bots/api).
2015-06-26 17:20:54 +00:00
```
npm install telegram-api
2015-06-26 17:20:54 +00:00
```
# Example
```javascript
var Bot = require('./index');
2015-06-26 17:20:54 +00:00
var smartBot = new Bot({
token: 'YOUR_KEY'
2015-06-26 17:20:54 +00:00
});
smartBot.start();
// You can use regular expressions, too
smartBot.get('Hi', function(update) {
const message = update.message;
const id = message.chat.id;
2015-06-26 17:20:54 +00:00
const question = 'How should I greet you?',
answers = ['Hi', 'Hello, Sir', 'Yo bro'];
smartBot.askQuestion(id, question, answers)
.then(answer => {
smartBot.message(id, 'Your answer: ' + answer);
2015-06-26 17:20:54 +00:00
}, () => {
smartBot.message(id, 'Invalid answer');
});
});
// Commands are in format `/command` or `/command@botusername` in groups
2015-06-26 17:20:54 +00:00
smartBot.command('test', update => {
const message = update.message;
const id = message.chat.id;
smartBot.message(id, 'Test command');
});
smartBot.command('start', update => {
smartBot.message(update.message.chat.id, 'Hello!');
});
// You can access all API methods through the api property until we implement
// easier methods
smartBot.api.getUserProfilePhotos
2015-06-26 17:20:54 +00:00
```
This will result in: