-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
85 lines (78 loc) · 2.55 KB
/
app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Sample inbound integration showing how to use Twilio Flex
* with Symbl's websocket API as the inbound audio stream
*/
/* import necessary modules for the web-socket API */
require("dotenv").config();
const express = require("express");
const app = express();
const server = require("http").createServer(app);
var path = require("path");
const sdk = require("symbl-node").sdk;
const bodyParser = require("body-parser");
const zoomParser = require("./zoomParser");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + "/"));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname + "/index.html"));
});
app.post("/join", (req, res) => {
const sample = req.body.meetingInvite;
const meetingName = req.body.meetingName;
const parser = zoomParser();
if (parser.isValid(sample)) {
const result = parser.parse(sample);
result.then((data) => {
sdk
.init({
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET,
basePath: "https://api.symbl.ai",
})
.then(() => {
console.log("SDK Initialized");
sdk
.startEndpoint({
endpoint: {
type: "pstn",
phoneNumber: data.joiningDetails[0].phoneNumbers[0],
dtmf: data.joiningDetails[0].dtmf,
},
actions: [
{
invokeOn: "stop",
name: "sendSummaryEmail",
parameters: {
emails: [req.body.email],
},
},
],
data: {
session: {
name: meetingName,
},
},
})
.then((connection) => {
const connectionId = connection.connectionId;
console.log("Successfully connected.", connectionId);
res.sendFile(path.join(__dirname + "/success.html"));
})
.catch((err) => {
console.error("Error while starting the connection", err);
res.sendFile(path.join(__dirname + "/error.html"));
});
})
.catch((err) => {
console.error("Error in SDK initialization.", err);
res.sendFile(path.join(__dirname + "/error.html"));
});
});
} else {
res.sendFile(path.join(__dirname + "/error.html"));
}
});
var port = process.env.PORT || 5000;
app.listen(port, function () {
console.log("Symbl Personal Assistant app listening on port " + port + "!");
});