Skip to content

Instantly share code, notes, and snippets.

@rizaumami
Created September 12, 2017 04:12
Show Gist options
  • Save rizaumami/a24fc5dcf4d15a7f2175137e90d336a9 to your computer and use it in GitHub Desktop.
Save rizaumami/a24fc5dcf4d15a7f2175137e90d336a9 to your computer and use it in GitHub Desktop.
Bot Telegram yang dipasang di zeit.co/now. Lihat https://www.rizaumami.com/2017/09/membuat-bot-telegram-selamat-datang.html.
const escapeHtml = require('escape-html')
const Telegraf = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
function getName(user) {
let name = `<b>${escapeHtml(user.first_name)}</b>`
if (user.last_name) name += ` <b>${escapeHtml(user.last_name)}</b>`
if (user.username) name += ` (@${user.username})`
name += ` [<code>${user.id}</code>]`
return name
}
bot.on('message', (ctx) => {
if (ctx.updateSubTypes == 'new_chat_members') {
ctx.replyWithHTML(
`Hai ${getName(ctx.message.new_chat_member)}, selamat datang di <b>${ctx.chat.title}</b>!`, {
'reply_to_message_id': ctx.message.message_id,
'reply_markup': {
'inline_keyboard': [
[
{
text: 'Harap baca ini dulu',
url: 'http://telegraf.js.org'
}
]
]
}
}
)
}
})
const secret = Math.random().toString(36).slice(2)
bot.telegram.setWebhook(`${process.env.NOW_URL}/${secret}`)
bot.startWebhook(`/${secret}`, null, process.env.PORT, process.env.HOST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment