-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
51 lines (40 loc) · 1.31 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
const dasha = require("@dasha.ai/sdk");
const { v4: uuidv4 } = require("uuid");
const express = require("express");
const cors = require("cors");
const expressApp = express();
expressApp.use(express.json());
expressApp.use(cors());
const main = async () => {
const app = await dasha.deploy(`${__dirname}/app`);
await app.start({ concurrency: 10 });
expressApp.get("/sip", async (req, res) => {
const domain = app.account.server.replace("app.", "sip.");
const endpoint = `wss://${domain}/sip/connect`;
// client sip address should:
// 1. start with `sip:reg`
// 2. to be unique
// 3. use the domain as the sip server
const aor = `sip:reg-${uuidv4()}@${domain}`;
res.send({ aor, endpoint });
});
expressApp.post("/call", async (req, res) => {
const { aor, name } = req.body;
res.sendStatus(200);
console.log("Start call for", req.body);
const conv = app.createConversation({ endpoint: aor, name });
conv.on("transcription", console.log);
conv.audio.tts = "dasha";
conv.audio.noiseVolume = 0;
await conv.execute();
});
const server = expressApp.listen(8000, () => {
console.log("Api started on port 8000.");
});
process.on("SIGINT", () => server.close());
server.once("close", async () => {
await app.stop();
app.dispose();
});
};
main();