-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQOTD.js
39 lines (34 loc) · 966 Bytes
/
QOTD.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
import xapi from 'xapi';
xapi.config.set('HttpClient Mode', 'On');
//
// This macro is built around the way this quote server responds.
//
const url = 'https://api.quotable.io/random?maxLength=105';
//
// get a random quote from the quote server
// repeat if quote length is > 128 characters (max CustomMessage size)
//
async function* getQuote(Url) {
while (true) {
const result = await xapi.Command.HttpClient.Get({Url})
const data = JSON.parse(result.Body)
const quote = data.author + ": " + data.content
if (quote.length <= 128) {
yield quote
return
} else {
yield false
await new Promise((resolve) => setTimeout(resolve, 500))
}
}
}
//
// When a call hangs up, get the quote and update CustomMessage
//
xapi.event.on('CallDisconnect', async (event) => {
let quote
for await (const result of getQuote(url)) {
quote = result
}
xapi.Config.UserInterface.CustomMessage.set(quote)
})