npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

botmaster-telegram

v1.1.0

Published

The telegram integration for Botmaster

Downloads

14

Readme

Botmaster-telegram

Build Status

npm-version license

This is the Telegram integration for botmaster. It allows you to use your botmaster bot on Telegram.

This package works with botmaster v3;

Botmaster is a lightweight chatbot framework. Its purpose is to integrate your existing chatbot into a variety of messaging channels.

Documentation

Find the whole documentation for the framework on: http://botmasterai.com/documentation.latest

Installing

yarn add botmaster-telegram

or

npm install --save botmaster-telegram

Credentials

All you need here is an authToken. In order to get one, you will need to either create a new bot on telegram.

Basically, you'll need to send a /newbot command(message) to Botfather (go talk to him here). Once you're done with giving it a name and a username, BotFather will come back to you with your authToken. Make sure to store it somewhere. More info on BotFather can be found here if needed.

For more on Telegram, you can find the telegram api docs here

Webhooks

Setting up your webhook requires you to make the following request outside of Botmaster (using curl for instance or a browser):

https://api.telegram.org/bot<authToken>/setWebhook?url=<'Your Base URL'>/telegram/webhook1234

Because Telegram doesn't send any type of information to verify the identity of the origin of the update, it is highly recommended that you include a sort of hash in your webhookEndpoint. I.e., rather than having this: webhookEndpoint: '/webhook/', do something more like this: webhookEndpoint: '/webhook92ywrnc9qm4qoiuthecvasdf42FG/'. This will assure that you know where the request is coming from.

If you are not too sure how webhooks work and/or how to get them to run locally, go to webhooks to read some more.

Code

const Botmaster = require('botmaster');
const TelegramBot = require('botmaster-telegram');
const botmaster = new Botmaster();

const telegramSettings = {
  credentials: {
    authToken: 'YOUR authToken',
  },
  webhookEndpoint: '/webhook1234/',
};

const telegramBot = new TelegramBot(telegramSettings);
botmaster.addBot(telegramBot);

botmaster.use({
  type: 'incoming',
  name: 'my-middleware',
  controller: (bot, update) => {
    return bot.reply(update, 'Hello world!');
  }
});

Note on attachment types and conversions

Attachment type conversion works as such for Telegram:

| Telegram Type | Botmaster conversion |--- |--- | audio | audio | voice | audio | photo | image | video | video | location | location | venue | location

contact attachment types aren't supported in Messenger. So in order to deal with them in Botmaster, you will have to look into your update.raw object which is the standard Telegram update. You will find your contact object in update.raw.contact.

Also, concerning location and venue attachments. The url received in Botmaster for Telegram is a google maps one with the coordinates as query parameters. It looks something like this: https://maps.google.com/?q=<lat>,<long>

A few of you will want to use attachments with your socket.io bots. Because the Botmaster message standard is the Facebook Messenger one, everything is URL based. Which means it is left to the developer to store both incoming and outgoing attachments.

License

This library is licensed under the MIT license