A class that can send and receive telegram messages, that has a clean and simple speak/listen API.
Works in concert with rsf-telegram-bot.
npm install --save rsf-telegramable
The id
property of a person config should be like the following:
username
In a person config, use type telegram
to specify a Telegramable
{
"type": "telegram",
"id": "myusername"
}
You must be running an instance of rsf-telegram-bot to connect to via websockets in order for the following to work. Say that is running on localhost, on port 3022...
const { init, shutdown, Telegramable } = require('rsf-telegramable')
const config = {
socketUrl: 'ws://localhost:3022'
}
init(config).then(() => {
const person = new Telegramable('tgusername')
// log anything that we hear from them
person.listen(console.log)
person.speak('hello!')
// after 5 seconds, shutdown/disconnect
// person methods will no longer work, or be fired
setTimeout(() => {
shutdown()
}, 5000)
})