Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.

Commit 0406380

Browse files
committed
feat(lib): add event for recieve response message
1 parent 7b2710f commit 0406380

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ export class Bot extends (EventEmitter as { new(): EventType<IBot> }) {
1919
constructor(option?: Partial<IOption>) {
2020
super()
2121
if (option) Bot.setOption(option)
22+
23+
this.init().then(events => { // mapping events from https://developer.byteball.org/list-of-events
24+
events.on('text', (...r) => this.emit('message', {
25+
from_address: r[0],
26+
text: r[1],
27+
count: r[2],
28+
response: (txt: string) => this.sendMessage(r[0], txt)
29+
}))
30+
}).catch(err => this.emit('error', err))
31+
}
32+
33+
sendMessage(to_address: string, message: string) {
34+
if (!this._device) throw new Error('Bot not ready')
35+
else this._device.sendMessageToDevice(to_address, 'text', message)
2236
}
2337

2438
private async init() {

0 commit comments

Comments
 (0)