-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.43 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
import { relay } from '@relaypro/sdk'
import helloworld from './workflows/helloworld.js'
import deviceinfo from './workflows/deviceinfo.js'
import interval from './workflows/interval.js'
import notification from './workflows/notification.js'
import vibrate from './workflows/vibrate.js'
import coffee from './workflows/coffee.js'
import timer from './workflows/timer.js'
import axios from 'axios'
import querystring from 'querystring'
import express from 'express'
export const wfs = []
const express1 = express()
const port = process.env.PORT || 3000
express1.post('/msg', (req, res) => {
console.log(`Request to /msg`)
let data = req.body
eventEmitter.emit(`http_event`, data)
res.send("Received")
})
const server = express1.listen(port, () => {
console.log(`express listening on ${port}`)
})
const app = relay({server})
// "named" workflows must match the WS path
// e.g. wss://host:port/helloworld
app.workflow(`helloworld`, helloworld)
app.workflow(`deviceinfo`, deviceinfo)
app.workflow(`interval`, interval)
app.workflow(`notification`, notification)
app.workflow(`vibrate`, vibrate)
app.workflow(`coffee`, coffee)
app.workflow(`timer`, timer)
// only one "un-named" workflow allowed...
// e.g. wss://host:port/
// e.g. wss://host:port
// enabled by setting ENV parameter:
// STRICT_PATH=1 node index.js
app.workflow(relay => {
relay.on(`start`, async () => {
relay.say(`This is a default workflow`)
relay.terminate()
})
})