This repository was archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend-api-bot.ts
More file actions
62 lines (58 loc) · 1.71 KB
/
send-api-bot.ts
File metadata and controls
62 lines (58 loc) · 1.71 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import http = require('http');
import platform = require('../index');
import { sendMessage, messageTo, webhookApi } from '../index';
const PAGE_TOKEN = 'TOKEN';
function delay(ms: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
http
.createServer(
platform
.createServer({
verificationToken: 'test',
})
.onTextMessage(async (testMessage: webhookApi.MessageReceivedEvent) => {
await delay(1000);
console.log('sending mark_seen');
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender).action('mark_seen'),
);
await delay(1000);
console.log('sending text msg');
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender).text('This is a simple text message'),
);
await delay(1000);
console.log('sending typing_on');
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender).action('typing_on'),
);
await delay(2000);
console.log('sending typing_off');
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender).action('typing_off'),
);
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender).image(
'https://just-comments.com/widget/no-pic.png',
),
);
await delay(1000);
await sendMessage(
PAGE_TOKEN,
messageTo(testMessage.sender)
.text('Answer the question: In which country is Stuttgart located?')
.quickTextReply('Germany', 'GER')
.quickLocationReply(),
);
})
.done(),
)
.listen(3000);