Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}))
}
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)
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' }
})
},
}
// 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
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;
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;
}
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);
};
constructor() {
this.bot = new TelegramBot(process.env.TELEGRAM_TOKEN, {
polling: true
});
this.store = store();
}
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;
}