transport-telegram.js
932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
const TelegramBot = require('node-telegram-bot-api');
const config = require('komodo-sdk/config')
const logger = require('komodo-sdk/logger');
const bot = new TelegramBot(config.transport.token, {polling: true});
bot.on('message', (msg) => {
const chatId = msg.chat.id;
// send a message to the chat acknowledging receipt of their message
bot.sendMessage(chatId, 'Received your message');
});
function init(cb) {
if (!cb) {
logger.warn('Callback is not defined');
console.trace();
process.exit(1);
return;
}
_callback = cb;
bot.connect({
jid: config.username,
password: config.password,
host: config.xmpp_host
});
}
function send(partner, msg) {
logger.verbose('Sending message via transport', {transport: 'telegram', partner: partner, msg: msg});
//bot.send(partner, msg);
}
exports.init = init;
exports.send = send;