Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (71 loc) · 2.53 KB
/
Copy pathindex.js
File metadata and controls
79 lines (71 loc) · 2.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const Rx = require("rxjs/Rx");
const R = require("ramda");
const Rx = require("rxjs/Rx");
const R = require("ramda");
const BroidCallr = require("broid-callr");
const BroidDiscord = require("broid-discord");
const BroidFlowdock = require("broid-flowdock");
const BroidLine = require("broid-line");
const BroidKik = require("broid-kik");
const BroidMessenger = require("broid-messenger");
const BroidSkype = require("broid-skype");
const BroidSlack = require("broid-slack");
const BroidTelegram = require("broid-telegram");
const BroidTwilio = require("broid-twilio");
const BroidTwitter = require("broid-twitter");
const BroidViber = require("broid-viber");
const clients = {
callr: new BroidCallr({<config>}),
discord: new BroidDiscord({<config>}),
flowdock: new BroidFlowdock({<config>});
line: new BroidLine({<config>}),
kik: new BroidKik({<config>}),
messenger: new BroidMessenger({<config>}),
skype: new BroidSkype({<config>}),
slack: new BroidSlack({<config>}),
telegram: new BroidTelegram({<config>})
twitter: new BroidTwitter({<config>}),
twilio: new BroidTwilio({<config>}),
viber: new BroidViber({<config>}),
};
Rx.Observable.merge(...R.map(client => client.connect(), R.values(clients)))
.subscribe({
next: data => console.log(JSON.stringify(data, null, 2)),
error: err => console.error(`Something went wrong: ${err.message}`),
});
Rx.Observable.merge(...R.map(client => client.listen(), R.values(clients)))
.subscribe({
next: message => {
if (message.type === "Create") {
const to = R.path(["target", "id"], data);
const to_type = R.path(["target", "type"], data);
const content = R.path(["object", "content"], data);
const service_id = R.path(["generator", "id"], data);
const service_name = R.path(["generator", "name"], data);
const type = R.path(["object", "type"], data);
if (type === "Note" && content.toLowerCase() === "hello world") {
const message = {
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Create",
"generator": {
"id": service_id,
"type": "Service",
"name": service_name
},
"object": {
"type": "Note",
"content": "Hello, how are you?"
},
"to": {
"type": to_type,
"id": to
}
};
clients[service_name].send(message)
.then(console.log)
.catch(console.error);
}
}
},
error: err => console.error(`Something went wrong: ${err.message}`),
});