Compare View
Commits (2)
Changes
Showing 3 changed files Side-by-side Diff
lib/transport.js
... | ... | @@ -15,6 +15,13 @@ const bot = new Telegraf(config.telegram.token); |
15 | 15 | |
16 | 16 | bot.start((ctx) => ctx.reply('Selamat datang. Silahkan ketik "HELP" untuk bantuan.')); |
17 | 17 | |
18 | +bot.command('help', (ctx) => { | |
19 | + sendToMessagingService( | |
20 | + ctx.from.username + ( config.username_suffix || '@telegram.org' ), | |
21 | + 'help' | |
22 | + ) | |
23 | +}) | |
24 | + | |
18 | 25 | bot.catch((err) => { |
19 | 26 | logger.warn('Error catched', {err: err}); |
20 | 27 | }) |
... | ... | @@ -68,6 +75,20 @@ async function send(partner, msg) { |
68 | 75 | bot.telegram.sendMessage(chatId, msg); |
69 | 76 | } |
70 | 77 | |
78 | +function sendToMessagingService(partner, msg) { | |
79 | + if (!msg || (typeof msg === 'string' && !msg.trim())) { | |
80 | + return; | |
81 | + } | |
82 | + | |
83 | + if (messagingService && messagingService.onIncomingMessage) { | |
84 | + messagingService.onIncomingMessage({ | |
85 | + me: bot.context.botInfo.username, | |
86 | + partner: partner, | |
87 | + msg: msg.trim() | |
88 | + }) | |
89 | + } | |
90 | +} | |
91 | + | |
71 | 92 | bot.launch().then(() => { |
72 | 93 | logger.info(`Connected to Telegram Bot API as "@${ bot.context.botInfo.username }"`); |
73 | 94 | }); |
package-lock.json