Last active
August 23, 2024 09:40
-
-
Save rizaumami/a24fc5dcf4d15a7f2175137e90d336a9 to your computer and use it in GitHub Desktop.
Bot Telegram yang dipasang di zeit.co/now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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