Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

untitled notebook

node v10.24.1
version: 1.0.0
endpointsharetweet
const TelegramBot = require("node-telegram-bot-api") const request = require('request') telegram = new TelegramBot("933675660:AAEjMDCRinoa24KNQlrASNpWPDte4V8NWSw", { polling: true }) telegram.on("message", (message) => { console.log(message) request('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', { json: true }, (err, res, body) => { if (err) { return console.log(err); } // if (message.entities) { console.log(message.entities.map(e => e.type)) } if (message.text) { switch(message.text) { case '/start start': telegram.sendMessage(message.chat.id, 'Buondì') break case '/quote': telegram.sendPhoto(message.chat.id, body.url, {caption: body.explanation}) break case '/poll': telegram.sendPoll(message.chat.id, 'E se ti piace la frutta...', [ '...mangiatela tutta 🍌', '...ficcatela in 🍑' ]) break case '/poll-fake': telegram.sendMessage(message.chat.id, 'E se ti piace la frutta...', { "reply_markup": { "keyboard": [['...mangiatela tutta 🍌'], ['...ficcatela in 🍑']] } }) break default: telegram.sendSticker(message.chat.id,'CAADBAADTQADudGqAdq7Ovw87xphFgQ') } } }) }) telegram.sendPoll = sendPoll telegram.stopPoll = stopPoll /** * Send poll. * Use this method to send a native poll. * * @param {Number|String} chatId Unique identifier for the group/channel * @param {String} question Poll question, 255 char limit * @param {Array} pollOptions Poll options, between 2-10 options * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#sendpoll */ function sendPoll(chatId, question, pollOptions, form = {}) { form.chat_id = chatId; form.question = question; form.options = stringify(pollOptions); return this._request('sendPoll', { form }); } /** * Stop poll. * Use this method to stop a native poll. * * @param {Number|String} chatId Unique identifier for the group/channel * @param {Number} pollId Identifier of the original message with the poll * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#stoppoll */ function stopPoll(chatId, pollId, form = {}) { form.chat_id = chatId; form.message_id = pollId; return this._request('stopPoll', { form }); } /** * JSON-serialize data. If the provided data is already a String, * return it as is. * @private * @param {*} data * @return {String} */ function stringify(data) { if (typeof data === 'string') { return data; } return JSON.stringify(data); }
Loading…

no comments

    sign in to comment