-
Notifications
You must be signed in to change notification settings - Fork 6
/
socket.js
50 lines (42 loc) · 1.45 KB
/
socket.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
const { SocketClient, isMessageType } = require('../');
const config = require('./config');
const client = new SocketClient(config);
console.log('Supported MessageSenders by SocketClient', client.getMessageSenders());
// Listen and react to socket messages
client.on(
'message',
client.getMessageHandler(message => {
console.log('Message Received', message);
if (isMessageType(message, 'text')) {
const text = message.data.data.toLowerCase();
if (text === 'button') {
return client.sendButton(
{
label: 'Open Node.js Client SDK',
color: '#FF0000',
action: 'https://github.com/wangshijun/mixin-node-client',
},
message
);
}
if (text === 'contact') {
return client.sendContact('7701e7bf-2a86-4655-982e-023564fa8945', message);
}
if (text === 'app') {
return client.sendApp(
{
icon_url:
'https://images.mixin.one/PQ2dYjNNXYYCCcSi_jDxrh0PJM8XBaiwu4I5_5e7tJhpQNbCVULnc5VRzR4AHF2e7AK6mVpvaHxO0EZr24cUjbg=s256',
title: 'Mixin Node.js SDK',
description: 'Utilities to easy Mixin dapp development',
action: 'https://github.com/wangshijun/mixin-node-client',
},
message
);
}
return client.sendText('Hi there!', message);
}
return Promise.resolve(message);
})
);
client.on('error', err => console.error(err.message));