-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (55 loc) · 1.73 KB
/
index.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
57
58
59
60
const TurnIntegration = require('@turnio/integration')
/* IMPORTANT!
* You need to get the integration secret from your Turn integrations settings
* and set it up as an env variable called `SECRET` in your Replit.
*/
const turn_integration_secret = process.env.SECRET
if (process.env.SECRET == undefined) {
console.error("[ERROR!] You forgot to set your integration secret as an enviroment variable.")
process.exit(1)
}
const app = new TurnIntegration(turn_integration_secret)
.context('Language', 'table', ({ chat, messages }) => ({
Language: 'English',
Confidence: 'Very high'
}))
.context('A list of things', 'ordered-list', ({ chat, messages }) => [
'first item',
'second item',
'third item'
])
.suggest(({ chat, messages }) => [
{
type: 'TEXT',
title: 'Password reset',
body: 'To reset your password click the link on the login page.',
confidence: 0.4
}
])
.action(({ chat, messages }) => [
{
description: 'Change Language',
payload: {
really: 'yes'
},
options: {
afr_ZA: 'Afrikaans',
eng_ZA: 'English',
zul_ZA: 'Zulu'
},
callback: ({ message, option, payload: { really } }, resp) => {
console.log({ message, option, really })
// Notify the frontend to refresh the context by setting
// the response header
resp.setHeader('X-Turn-Integration-Refresh', 'true')
// this is return as JSON in the HTTP response
return { ok: 'done' }
}
}
])
.serve()
const port = process.env.PORT || 3000
app.listen(port, () => {
replit_url = `https://${ process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`
console.log(`Turn UI integration running at ${replit_url}`)
})