How to use node-telegram-bot-api - 9 common examples

To help you get started, we’ve selected a few node-telegram-bot-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github telemmo / telemmo / src / engine / providers / telegram.js View on Github external
console.log(`Worker ${worker.process.pid} died`)
    })

    const bot = new TelegramBot(token)

    return bot.setWebHook(`${domain}:${options.webHook.port}/bot${token}`, {
      certificate: options.webHook.cert,
    })
      .then(bot.getMe.bind(bot))
      .then(always({
        send: partial(sendMessage, [bot]), // => Stream
        subscribe: () => Observable.empty(),
      }))
  }

  const bot = new TelegramBot(token, options)
  const stream = Observable.fromEvent(bot, 'message')

  if (process.env.NODE_ENV !== 'production') {
    stream.subscribe(console.log)
  }

  console.log(`Worker ${process.pid} started`)

  return bot.getMe()
    .then(always({
      send: partial(sendMessage, [bot]), // => Stream
      subscribe: partial(buildFilter, [stream]), // => Stream
    }))
}
github telemmo / telemmo / src / engine / providers / telegram.js View on Github external
cert: process.env.SSL_CERT_PATH,
    },
  }

  if (cluster.isMaster) {
    console.log(`Master ${process.pid} is running`)

    Array.from({ length: numWorkers }).forEach(() => {
      cluster.fork()
    })

    cluster.on('exit', (worker) => {
      console.log(`Worker ${worker.process.pid} died`)
    })

    const bot = new TelegramBot(token)

    return bot.setWebHook(`${domain}:${options.webHook.port}/bot${token}`, {
      certificate: options.webHook.cert,
    })
      .then(bot.getMe.bind(bot))
      .then(always({
        send: partial(sendMessage, [bot]), // => Stream
        subscribe: () => Observable.empty(),
      }))
  }

  const bot = new TelegramBot(token, options)
  const stream = Observable.fromEvent(bot, 'message')

  if (process.env.NODE_ENV !== 'production') {
    stream.subscribe(console.log)
github magic8bot / magic8bot / legacy / notifiers / telegram.ts View on Github external
pushMessage(title, message) {
      const bot = new TelegramBot(config.bot_token)

      bot.sendMessage(config.chat_id, title + ': ' + message).catch(function(error) {
        console.error('\nerror: telegram notification')
        console.log(error.response.body) // => { ok: false, error_code: 400, description: 'Bad Request: chat not found' }
      })
    },
  }
github artemgurzhii / TravisCI-Telegam-Bot / common.js View on Github external
// Requiing modules
import telegram from 'node-telegram-bot-api'; // telegram bot node api
import https from 'https';                    // make requests to travis json user data

// Telegram bot initialization
const token = '227706347:AAF-Iq5fV8L4JYdk3g5wcU-z1eK1dd4sKa0'; // authorization token
let bot = new telegram(token, {polling: true});                // initializing new bot

// main function to execute when getting message fom user
bot.on('text', msg => {

  let chatID = msg.chat.id; // saving user chat id from who bot received message
  let msgText = msg.text;   // getting text content from message

  // variables to declare in global scope
  let userID;      // slice msg to get user ID
  let userRepo;    // slice msg to get user Repository name
  let options;     // options for http request json data
  let prevBuild;   // storing number of previous build
  let currBuild;   // storing number of current build
  let currLink;    // storing here name of current link
  let linkMessage; // text message on /link command
  let slicing;     // using this variables for slicing user msg link
github telegram-ru / jobs-bot / bot.js View on Github external
const debug = require('debug')('jobs-bot:bot');
const TelegramBot = require('node-telegram-bot-api');

TelegramBot.prototype.deleteMessage = function deleteMessage(chatId, messageId, form = {}) {
  form.chat_id = chatId;
  form.message_id = messageId;
  return this._request('deleteMessage', { form });
};

debug('token', process.env.APP_BOT_TOKEN.split(':')[0]);

const bot = new TelegramBot(process.env.APP_BOT_TOKEN, { polling: true });

module.exports = bot;
github kiangkuang / WhoPick / src / app.js View on Github external
function initBot() {
    const token = process.env.BOT_TOKEN;

    if (!token) {
        throw "ERROR: env variables not set.";
    }

    if (process.env.NODE_ENV === "local") {
        return new TelegramBot(token, {
            polling: {
                params: { timeout: 2 }
            }
        });
    }
    const bot = new TelegramBot(token, {
        webHook: {
            port: process.env.PORT,
            host: "0.0.0.0"
        }
    });
    bot.setWebHook(
        `https://${process.env.HEROKU_APP_NAME}.herokuapp.com/bot${token}`
    );
    return bot;
}
github macecchi / PollyannaSpeechBot / src / telegram.js View on Github external
import TelegramBot from 'node-telegram-bot-api';

const Bot = new TelegramBot(process.env.TELEGRAM_TOKEN);

export const sendMessage = async (message, chatId) => {
  const { text, voice } = message;
  if (voice) {
    return Bot.sendVoice(chatId, voice, { caption: text });
  }

  return Bot.sendMessage(chatId, text);
};
github artemgurzhii / TravisCI-Telegam-Bot / src / lib / messenger.js View on Github external
constructor() {
		this.bot = new TelegramBot(process.env.TELEGRAM_TOKEN, {
			polling: true
		});
    this.store = store();
	}
github kiangkuang / WhoPick / src / app.js View on Github external
function initBot() {
    const token = process.env.BOT_TOKEN;

    if (!token) {
        throw "ERROR: env variables not set.";
    }

    if (process.env.NODE_ENV === "local") {
        return new TelegramBot(token, {
            polling: {
                params: { timeout: 2 }
            }
        });
    }
    const bot = new TelegramBot(token, {
        webHook: {
            port: process.env.PORT,
            host: "0.0.0.0"
        }
    });
    bot.setWebHook(
        `https://${process.env.HEROKU_APP_NAME}.herokuapp.com/bot${token}`
    );
    return bot;
}

node-telegram-bot-api

Telegram Bot API

MIT
Latest version published 6 months ago

Package Health Score

81 / 100
Full package analysis

Popular node-telegram-bot-api functions