Commit 27a8745e1f7bd96293e98fb1479f43d61f9b9e50
1 parent
7d8f701d8a
Exists in
master
skeleton
Showing 4 changed files with 79 additions and 0 deletions Side-by-side Diff
.gitignore
index.js
package.json
... | ... | @@ -0,0 +1,28 @@ |
1 | +{ | |
2 | + "name": "komodo-center-telegram", | |
3 | + "version": "0.9.0", | |
4 | + "description": "Komodo Center using Telegram transport", | |
5 | + "main": "index.js", | |
6 | + "scripts": { | |
7 | + "test": "mocha" | |
8 | + }, | |
9 | + "repository": { | |
10 | + "type": "git", | |
11 | + "url": "git@gitlab.kodesumber.com:komodo/komodo-center-telegram.git" | |
12 | + }, | |
13 | + "keywords": [ | |
14 | + "ppob", | |
15 | + "komodo", | |
16 | + "telegram" | |
17 | + ], | |
18 | + "author": "Adhidarma Hadiwinoto <me@adhisimon.org>", | |
19 | + "license": "ISC", | |
20 | + "devDependencies": { | |
21 | + "should": "^13.2.1" | |
22 | + }, | |
23 | + "dependencies": { | |
24 | + "komodo-sdk": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", | |
25 | + "node-telegram-bot-api": "^0.30.0", | |
26 | + "request": "^2.83.0" | |
27 | + } | |
28 | +} |
transport-telegram.js
... | ... | @@ -0,0 +1,40 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const TelegramBot = require('node-telegram-bot-api'); | |
4 | + | |
5 | +const config = require('komodo-sdk/config') | |
6 | +const logger = require('komodo-sdk/logger'); | |
7 | + | |
8 | +const bot = new TelegramBot(config.transport.token, {polling: true}); | |
9 | + | |
10 | +bot.on('message', (msg) => { | |
11 | + const chatId = msg.chat.id; | |
12 | + | |
13 | + // send a message to the chat acknowledging receipt of their message | |
14 | + bot.sendMessage(chatId, 'Received your message'); | |
15 | +}); | |
16 | + | |
17 | +function init(cb) { | |
18 | + if (!cb) { | |
19 | + logger.warn('Callback is not defined'); | |
20 | + console.trace(); | |
21 | + process.exit(1); | |
22 | + return; | |
23 | + } | |
24 | + | |
25 | + _callback = cb; | |
26 | + | |
27 | + bot.connect({ | |
28 | + jid: config.username, | |
29 | + password: config.password, | |
30 | + host: config.xmpp_host | |
31 | + }); | |
32 | +} | |
33 | + | |
34 | +function send(partner, msg) { | |
35 | + logger.verbose('Sending message via transport', {transport: 'telegram', partner: partner, msg: msg}); | |
36 | + //bot.send(partner, msg); | |
37 | +} | |
38 | + | |
39 | +exports.init = init; | |
40 | +exports.send = send; |