-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (46 loc) · 1.41 KB
/
main.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
49
50
51
52
53
54
55
56
const express = require('express');
const line = require('@line/bot-sdk');
const app = express();
const config = {
channelAccessToken: '',
channelSecret: ''
};
const client = new line.Client(config);
// webhook callback
app.post('/', line.middleware(config), (req, res) => {
if (req.body.destination) {
}
// req.body.events should be an array of events
if (!Array.isArray(req.body.events)) {
return res.status(500).end();
}
// handle events separately
Promise.all(req.body.events.map(handleEvent))
.then(() => res.end())
.catch((err) => {
console.error("An handle error appened : " + err);
res.status(500).end();
});
});
// simple getmembers function
function GetGroupMembers(GroupId) {
console.log('group id : ' + GroupId)
client.getGroupMemberProfile(GroupId)
.then((members) => console.log('ids : ' + members))
.catch((err) => {
console.log("An getmembers error appened : " + err)
});
};
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
return Promise.resolve(null);
};
if (event.source.type == 'group' && event.message.text == '.tagall') {
return handleGroup(event.source.groupId, event.replyToken);
};
return Promise.resolve(null);
};
function handleGroup(GroupId, replyToken) {
memberIds = GetGroupMembers(GroupId);
};
app.listen(3000);