Socket
Socket
Sign inDemoInstall

hubot-telegram

Package Overview
Dependencies
137
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hubot-telegram

Hubot adapter for Telegram


Version published
Weekly downloads
16
increased by220%
Maintainers
2
Install size
9.71 MB
Created
Weekly downloads
 

Readme

Source

Hubot Telegram Adapter

Build Status

Hubot adapter for interfacting with the Telegram Bot API

Installation & Usage

First of read the docs on how to create a new Telegram Bot. Once you have a bot created, follow these steps:

  • npm install --save hubot-telegram
  • Set the environment variables specified in Configuration
  • Run hubot bin/hubot -a telegram

Configuration

This adapter uses the following environment variables:

TELEGRAM_TOKEN (required)

The token that the BotFather gives you

TELEGRAM_INTERVAL (optional)

You can specify the interval (in milliseconds) in which the adapter will poll Telegram for updates. This option only applies if you are not using a webhook.

TELEGRAM_WEBHOOK (optional)

You can specify a webhook URL. The adapter will register TELEGRAM_WEBHOOK/TELEGRAM_TOKEN with Telegram and listen there.

Telegram Specific Functionality (ie. Stickers, Images)

The adapter will enhance the Response object with some custom methods with the same signature of the APIs. For example, sending an image:

module.exports = function (robot) {
  robot.hear(/send totoro/i, res => {
    const image = fs.createReadStream(__dirname + '/image.png')
    // https://core.telegram.org/bots/api#sendphoto
    res.sendPhoto(res.envelope.room, image, {
      caption: 'Totoro!'
    })
  })
}

Note: An example script of how to use this is located in the example/ folder

The list of methods exposed through a middleware to the response object is:

  • sendMessage
  • sendMessage
  • sendPhoto
  • sendAudio
  • sendDocument
  • sendMediaGroup
  • sendSticker
  • sendVideo
  • sendVideoNote
  • sendVoice
  • sendChatAction

If you want to supplement your message delivery with extra features such as markdown syntax or keyboard replies, you can specify these parameters on the options of sendMessage:

robot.respond(/(.*)/i, res => {
  res.sendMessage(
    res.envelope.room,
    'Select the option from the keyboard specified.',
    {
      reply_markup: {
        keyboard: [['Start', 'Stop']]
      }
    }
  )
})

inlineQuery are a way to reply without a conversation to the bot. That's why they don't really fit into the normal hear/respond flow of Hubot. To support inlineQuery you can listen to event on the telegram object exposed by the robot object.

module.exports = function (robot) {
  robot.telegram.on('inline_query', async inlineQuery => {
    // Initially there is always a query with empty string
    // Usually is to provide suggestions
    if (inlineQuery.query) {
      const searches = await google.search(inlineQuery.query, 50) // Max 50 results for inlineQuery
      const results = searches.map(result => ({
        type: 'photo',
        id: result.id,
        thumb_url: result['thumbnail'],
        photo_url: result['url']
      }))
      robot.telegram.answerInlineQuery(inlineQuery.id, results)
    }
  })
}

Contributors

Keywords

FAQs

Last updated on 08 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc