-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
48 lines (43 loc) · 1.07 KB
/
test.js
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
41
42
43
44
45
46
47
48
const app = require('express')();
const ChatBot = require('./index');
// In your app, you should use:
// const ChatBot = require('synology-chat-bot');
const token = 'YOUR_TOKEN_HERE';
const url = 'http://example.com:5000';
const port = 6666;
const chatbotApp = new ChatBot(token, url, app);
// setup the root for chatbot outgoing
chatbotApp.route('/');
/**
* outgoing request contains
*
* token
* user_id
* username
* post_id
* timestamp
* text
*/
chatbotApp.on('request', (outgoingRequest, response, next) => {
console.log('ggggg request: ', outgoingRequest.text);
if (outgoingRequest.text === 'hi') {
response.send(new ChatBot.Message('hi there'));
} else {
response.end();
}
});
// listen on port
app.listen(port);
// do something interesting...
// send message via user id
const userId = 5;
chatbotApp.send([userId], new ChatBot.Message('hi 5'))
.then(() => {})
.catch(() => {});
// send message via username
const username = 'admin';
chatbotApp.sendByUserName([username], new ChatBot.Message('hi admin'))
.then(() => {})
.catch((err) => {
console.log(err);
});