Deprecated: A simple API to create and control Telegram bots
Go to file
2015-06-28 05:34:18 +04:30
lib new version 2015-06-28 05:34:18 +04:30
.gitignore initial commit 2015-06-26 21:50:54 +04:30
demo.gif smaller GIF 2015-06-27 04:50:25 +04:30
demo.js new version 2015-06-28 05:34:18 +04:30
index.js initial commit 2015-06-26 21:50:54 +04:30
LICENSE Initial commit 2015-06-26 03:04:01 +04:30
package.json Bump version to 1.1 2015-06-27 04:26:47 +04:30
README.md a little more beautiful 2015-06-27 05:26:07 +04:30

Telegram Bots

Create and control Telegram bots easily using the new Telegram API.

telegram-api is in beta, your feedback is highly appreciated, please fill an issue for any bugs you find or any suggestions you have.

npm install telegram-api

Example

Take a look at demo.js. Also @JavaScriptBot, still work in progress.

var Bot = require('telegram-api');

var smartBot = new Bot({
  token: 'YOUR_KEY'
});

// getMe is called before polling starts, setting info property of bot
smartBot.start().then(() => {
  console.log(smartBot.info);
});

// You can use regular expressions, too
smartBot.get('Hi', function(update) {
  const message = update.message;
  const id = message.chat.id;

  // answers is in format of keyboard rows
  const question = 'How should I greet you?',
        answers = [['Hi'], ['Hello, Sir'], ['Yo bro']];

  smartBot.replyTo(message.message_id)
  .askQuestion(id, question, answers)
  .then(answer => {
    smartBot.message(id, 'Your answer: ' + answer);
  }, () => {
    smartBot.message(id, 'Invalid answer');
  });
});

// Commands are in format `/command` or `/command@botusername` in groups
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

This will result in:

@JavaScriptBot