Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

telegram-bot-bootstrap

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegram-bot-bootstrap

A bootstrap for Telegram bot with wrapped API and sample bot directly deployable to Heroku

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by160%
Maintainers
1
Weekly downloads
 
Created
Source

telegram-bot-bootstrap

A bootstrap for Telegram bot with directly deployable sample bot and JS-wrapped API methods.

See the full API documentation of this project.

Installation

If you wish to use only the wrapped Telegram API, do either of

npm install telegram-bot-bootstrap
git clone https://github.com/kengz/telegram-bot-bootstrap.git

Either way you'll get a module with the Telegram bot API wrapped in Node, and a bootstrapped, deploy-ready project.

If you haven't already, get a bot from BotFather and remember your bot token!

Features

  • Wrapped API methods take either a JSON object or multiple parameters, properly serialized for HTTP formData.
  • API methods return promises (uses q) for easy chaining and flow control.
  • Complete documentation and examples usages.
  • Bootstrapped and directly deployable bot.

Usage: only the API

See the full API documentation of this project.

API.js contains the Telegram Bot API wrapped in Node. The methods will return a promise for easy chaining, and will take either a whole JSON, or multiple parameters for convenience. For the latter, everything will be serialized properly for you to send over a HTTP POST method.

If you wish to use just the API or test the bot methods, here's an example

var bot = require('telegram-bot-bootstrap');

var Alice = new bot(token);

Alice.getUpdates().then(console.log)
// → you'll see an update message. Look for your user_id in "message.from.id"

// Once you get your id to message yourself, you may:
Alice.sendMessage(your-id, "Hello there")
// → you'll receive a message from Alice.
.then(console.log)
// → optional, will log the successful message sent over HTTP

Usage: Bootstrapped, Deployable Bot

We distinguish the bot from the API: bot.js extends API.js, and will be the deployed component.

This whole project is bootstrapped and deploy-ready: all the details of HTTP and server stuff taken care of for you. I deploy this git project onto my Heroku and voila, my bot is alive.

Setup

In addition to the token, you'll need a webhookUrl. If you deploy your Node app to Heroku, then the webhookUrl is simply your Heroku site url. Set both of them in the .env file:

TIMES=2
PORT=8443
TOKEN=your-Telegram-bot-token
WEBHOOK=your-webhook-url

The sample available is an echo-bot. To make your bot do interesting stuff, head over to bot.js, under the handle method, start writing your own from below the Extend from here comment.

The bot inherits all the API methods, so you can simply call them for example by this.sendMessage.

Deployment

The server is deployed in index.js, and a bot is constructed to handle all HTTP POST calls from Telegram.

I use Heroku. This shall work for any other services too. Once I'm done setting up, I do:

git push heroku master

And done. Start talking to the bot.

Keywords

FAQs

Package last updated on 29 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc