-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
100 lines (90 loc) · 3.1 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2022 Symbl.ai SDK contributors. All Rights Reserved.
// SPDX-License-Identifier: MIT
require('dotenv').config()
const {sdk, SpeakerEvent} = require('symbl-node')
const phoneNumber = undefined // replace this with the phone number, or configure DEFAULT_PHONE_NUMBER in .env file.
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: 'sip', // Use this if you're trying to dial in to a SIP trunk.
// uri: 'sip:username@domain.com',
type: 'pstn',
phoneNumber: phoneNumber || process.env.DEFAULT_PHONE_NUMBER //,
//dtmf: '', // you can find this on the meeting platform invite. Omit or leave blank if not connecting to a meeting platform
},
actions: [
{
invokeOn: 'stop',
name: 'sendSummaryEmail',
parameters: {
emails: [process.env.SUMMARY_EMAIL], // Add valid email addresses to received email
},
},
],
})
.then((connection) => {
const connectionId = connection.connectionId
console.log('Successfully connected.', connectionId)
const speakerEvent = new SpeakerEvent({
type: SpeakerEvent.types.startedSpeaking,
user: {
userId: 'john@example.com',
name: 'John',
},
})
setTimeout(() => {
speakerEvent.timestamp = new Date().toISOString()
sdk.pushEventOnConnection(
connectionId,
speakerEvent.toJSON(),
(err) => {
if (err) {
console.error('Error during push event.', err)
} else {
console.log('Event pushed!')
}
},
)
}, 1000)
setTimeout(() => {
speakerEvent.type = SpeakerEvent.types.stoppedSpeaking
speakerEvent.timestamp = new Date().toISOString()
sdk.pushEventOnConnection(
connectionId,
speakerEvent.toJSON(),
(err) => {
if (err) {
console.error('Error during push event.', err)
} else {
console.log('Event pushed!')
}
},
)
}, 12000)
// Scheduling stop endpoint call after 60 seconds
setTimeout(() => {
sdk
.stopEndpoint({
connectionId: connection.connectionId,
})
.then(() => {
console.log('Stopped the connection')
console.log('Summary Info:', connection.summaryInfo)
console.log('Conversation ID:', connection.conversationId)
})
.catch((err) =>
console.error('Error while stopping the connection.', err),
)
}, 10000)
})
.catch((err) => console.error('Error while starting the connection', err))
})
.catch((err) => console.error('Error in SDK initialization.', err))