Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Modules documentation: https://telegraf.js.org/#/?id=telegraf-modules
// $> telegraf -t `BOT TOKEN` echo-bot-module.js
const Composer = require('telegraf/composer')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const keyboard = Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Markup.callbackButton('Delete', 'delete')
])
const bot = new Composer()
bot.start((ctx) => ctx.reply('Hello'))
bot.help((ctx) => ctx.reply('Help message'))
bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard)))
bot.action('delete', ({ deleteMessage }) => deleteMessage())
module.exports = bot
`, Extra.markup(keyboardCio));
})
.catch(error => ctx.reply(`Error: ${error}`));
}
catch (error) {
site.logger.info(`error: ${error}`, { route: `api/sense-bot/telegram::cioCustomerService()` });
}
});
/***************
* HELPDESK
**************/
// BUTTONS
const keyboardHelpdesk = Markup.inlineKeyboard([
[
Markup.urlButton('View Demo', 'https://demos.qlik.com/qliksense/HelpdeskManagement'),
Markup.callbackButton(config.text[lang].helpdesk.highPriorityCases.button, 'helpdeskHighPriorityCases')
],
[
Markup.callbackButton(config.text[lang].helpdesk.mediumPriorityCases.button, 'helpdeskMediumPriorityCases'),
Markup.callbackButton(config.text[lang].helpdesk.lowPriorityCases.button, 'helpdeskLowPriorityCases')
]
]);
// COMMANDS - ACTIONS
bot.command('helpdesk', (ctx) => {
try {
site.logger.info(`helpdesk-main`, { route: `api/sense-bot/telegram` });
ctx.reply(config.text[lang].helpdesk.welcome);
ctx.replyWithPhoto({ url: 'https://sense-demo-staging.qlik.com/appcontent/133dab5d-8f56-4d40-b3e0-a6b401391bde/helpdesk_management.jpg' });
ctx.telegram.sendCopy(ctx.from.id, ctx.message, Extra.markup(keyboardHelpdesk));
}
catch (error) {
${config.text[lang].salesforce.opportunities.kpi7}: <b>${result[6][0].qText}</b>
`, Extra.markup(keyboardSalesforce));
})
.catch(error => ctx.reply(`Error: ${error}`));
}
catch (error) {
site.logger.info(`error: ${error}`, { route: `api/sense-bot/telegram::salesforceOpportunities()` });
}
});
/***************
* CIO DASHBOARD
**************/
// BUTTONS
const keyboardCio = Markup.inlineKeyboard([
Markup.urlButton(config.text[lang].viewDemo, 'https://webapps.qlik.com/CIO/index.html'),
Markup.callbackButton(config.text[lang].cio.management.button, 'cioManagement'),
Markup.callbackButton(config.text[lang].cio.customer.button, 'cioCustomerService')
]);
// COMMANDS - ACTIONS
bot.command('cio', (ctx) => {
try {
site.logger.info(`cio-main`, { route: `api/sense-bot/telegram` });
ctx.reply(config.text[lang].cio.welcome);
ctx.replyWithPhoto({ url: 'https://sense-demo-staging.qlik.com/appcontent/d0dd198f-138b-41d8-a099-5c5071bd6b33/CIO-desktop-development.jpg' });
ctx.telegram.sendCopy(ctx.from.id, ctx.message, Extra.markup(keyboardCio));
}
catch (error) {
site.logger.info(`error: ${error}`, { route: `api/sense-bot/telegram::cio()` });
}
});
bot.action('cioManagement', (ctx) => {
});
// bot.telegram.setWebhook('https://localhost:3443/api/sense-bot/telegram/adhoc/')
/*************
* MAIN
*************/
bot.use(session());
bot.start((ctx) => ctx.reply(config.text[lang].welcome));
/*************
* SALESFORCE
*************/
// BUTTONS
const keyboardSalesforce = Markup.inlineKeyboard([
Markup.urlButton(config.text[lang].viewDemo, 'https://webapps.qlik.com/salesforce/index.html'),
Markup.callbackButton(config.text[lang].salesforce.dashboard.button, 'salesforceDashboard'),
Markup.callbackButton(config.text[lang].salesforce.opportunities.button, 'salesforceOpportunities')
// Markup.callbackButton('Chart', 'salesforceChart')
]);
// COMMANDS - ACTIONS
bot.command('salesforce', (ctx) => {
try {
site.logger.info(`salesforce-main`, { route: `api/sense-bot/telegram` });
ctx.reply(config.text[lang].salesforce.welcome);
ctx.replyWithPhoto({ url: 'https://webapps.qlik.com/img/2017_salesforce.png' });
ctx.telegram.sendCopy(ctx.from.id, ctx.message, Extra.markup(keyboardSalesforce));
}
catch (error) {
site.logger.info(`error: ${error}`, { route: `api/sense-bot/telegram::salesforce()` });
}
});
const shippingOptions = [
{
id: 'unicorn',
title: 'Unicorn express',
prices: [{ label: 'Unicorn', amount: 2000 }]
},
{
id: 'slowpoke',
title: 'Slowpoke mail',
prices: [{ label: 'Slowpoke', amount: 100 }]
}
]
const replyOptions = Markup.inlineKeyboard([
Markup.payButton('💸 Buy'),
Markup.urlButton('❤️', 'http://telegraf.js.org')
]).extra()
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start(({ replyWithInvoice }) => replyWithInvoice(invoice))
bot.command('buy', ({ replyWithInvoice }) => replyWithInvoice(invoice, replyOptions))
bot.on('shipping_query', ({ answerShippingQuery }) => answerShippingQuery(true, shippingOptions))
bot.on('pre_checkout_query', ({ answerPreCheckoutQuery }) => answerPreCheckoutQuery(true))
bot.on('successful_payment', () => console.log('Woohoo'))
bot.launch()
(ctx) => {
ctx.reply('Step 1', Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Markup.callbackButton('➡️ Next', 'next')
]).extra())
return ctx.wizard.next()
},
stepHandler,
module.exports = async (ctx) => {
const quoteBot = await ctx.getChatMember(1031952739)
if (!['member', 'administrator'].includes(quoteBot.status)) {
ctx.replyWithHTML(ctx.i18n.t('cmd.quote'), {
reply_to_message_id: ctx.message.message_id,
reply_markup: Markup.inlineKeyboard([
Markup.urlButton(
ctx.i18n.t('private.btn_add'),
`https://t.me/QuotLyBot?startgroup=add`
)
])
})
}
}
const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const gameShortName = 'your-game'
const gameUrl = 'https://your-game.tld'
const markup = Extra.markup(
Markup.inlineKeyboard([
Markup.gameButton('🎮 Play now!'),
Markup.urlButton('Telegraf help', 'http://telegraf.js.org')
])
)
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start(({ replyWithGame }) => replyWithGame(gameShortName))
bot.command('foo', ({ replyWithGame }) => replyWithGame(gameShortName, markup))
bot.gameQuery(({ answerGameQuery }) => answerGameQuery(gameUrl))
bot.launch()
const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const keyboard = Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Markup.callbackButton('Delete', 'delete')
])
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Hello'))
bot.help((ctx) => ctx.reply('Help message'))
bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard)))
bot.action('delete', ({ deleteMessage }) => deleteMessage())
bot.launch()
.map(({ title, href, thumbnail }) => ({
type: 'article',
id: thumbnail,
title: title,
description: title,
thumb_url: thumbnail,
input_message_content: {
message_text: title
},
reply_markup: Markup.inlineKeyboard([
Markup.urlButton('Go to recipe', href)
])
}))
return answerInlineQuery(recipes)