Created
October 17, 2017 10:15
-
-
Save sabbaticaldev/1e329e42bb4abdc9946074d8c2956819 to your computer and use it in GitHub Desktop.
This file contains 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
var rn_bridge = require('rn-bridge'); | |
const { MTProto } = require('./node_modules/telegram-mtproto/lib') | |
const config = { | |
id: 48333, | |
hash: '620d2f971efe51f9a69539e13bfb1efa' | |
} | |
var telegram = MTProto({ | |
layer: 57, | |
api_id: config.id, | |
dev: true | |
}); | |
const run = async ({action = "ping", args = {}, attrs = []}) => { | |
try { | |
rn_bridge.channel.send(JSON.stringify({notice: "sending to telegram"})); | |
const result = await telegram(action, { | |
...args, | |
api_id : config.id, | |
api_hash : config.hash | |
}); | |
rn_bridge.channel.send(JSON.stringify({result, attrs})); | |
} | |
catch (e) { | |
rn_bridge.channel.send(JSON.stringify({error: e})); | |
} | |
}; | |
rn_bridge.channel.on('message', (msg) => { | |
var json = JSON.parse(msg); | |
setImmediate(() => run(json)); | |
}); | |
setInterval(() => { | |
rn_bridge.channel.send(JSON.stringify({result: "Ping!"})); | |
}, 30000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment