Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created August 26, 2020 01:14
Show Gist options
  • Save itacirgabral/50d1e2531eaababa5a43bd07391e4bbd to your computer and use it in GitHub Desktop.
Save itacirgabral/50d1e2531eaababa5a43bd07391e4bbd to your computer and use it in GitHub Desktop.
const { Telegraf } = require("telegraf");
const mk_bot = (dao, secretPath, hostname, botToken) => {
const bot = new Telegraf(botToken);
bot.telegram.setWebhook(`https://${hostname}/${secretPath}`);
bot.start(async ctx => {
ctx.reply(`Olá ${ctx.from.username}, eu sou um caixa eletrônico`)
});
bot.command('conta', async ctx => {
console.log('Chegou um mensalidade')
ctx.replyWithInvoice({
title: 'title',
description: 'description',
payload: 'payload',
provider_token: '284685063:TEST:MTQwNmMxM2UyZDJi',
start_parameter: 'cpZ20Jy87I8B8Kiy',
currency: 'BRL',
prices: [{ label: 'cpZ20Jy87I8B8Kiy', amount: 1000 }]
})
})
// Handle payment callbacks
bot.on('pre_checkout_query', ({ answerPreCheckoutQuery }) => answerPreCheckoutQuery(true))
bot.on('successful_payment', (ctx) => {
console.log(`${ctx.from.first_name} (${ctx.from.username}) acabou de pagar ${ctx.message.successful_payment.total_amount / 100} Reais.`)
})
bot.launch();
return bot;
}
module.exports = mk_bot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment