-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
133 lines (117 loc) · 3.99 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2022 Symbl.ai SDK contributors. All Rights Reserved.
// SPDX-License-Identifier: MIT
require('dotenv').config()
const {sdk, SpeakerEvent} = require('symbl-node')
const getScheduleEvent = (sdk, connectionId) => {
return (eventType, user, time) => {
setTimeout(() => {
const speakerEvent = new SpeakerEvent({
type: eventType,
user,
})
speakerEvent.timestamp = new Date().toISOString()
console.log(
`Pushing event [${speakerEvent.timestamp}] ${speakerEvent.type} : ${speakerEvent.user.name}`,
)
sdk.pushEventOnConnection(connectionId, speakerEvent.toJSON(), (err) => {
if (err) {
console.error('Error during push event.', err)
} else {
console.log('Event pushed!')
}
})
}, time * 1000)
}
}
const users = {
john: {
userId: 'john@example.com',
name: 'John',
},
mary: {
userId: 'mary@example.com',
name: 'Mary',
},
}
;(async () => {
try {
// Initialize the SDK
await sdk.init({
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET,
basePath: 'https://api.symbl.ai',
})
console.log('SDK Initialized')
const connection = await sdk.startEndpoint({
endpoint: {
type: 'pstn',
phoneNumber: process.env.DEFAULT_PHONE_NUMBER,
},
insightTypes: ['action_item', 'question'],
actions: [
{
invokeOn: 'stop',
name: 'sendSummaryEmail',
parameters: {
emails: [process.env.SUMMARY_EMAIL], // Add valid email addresses to received email
},
},
],
data: {
session: {
name: 'My Test Meeting',
},
},
})
const connectionId = connection.connectionId
console.log('Successfully connected. Connection ID: ', connectionId)
const scheduleEvent = getScheduleEvent(sdk, connectionId)
setTimeout(() => {
// Schedule all the events to be sent.
scheduleEvent(SpeakerEvent.types.startedSpeaking, users.john, 0)
scheduleEvent(SpeakerEvent.types.stoppedSpeaking, users.john, 5)
scheduleEvent(SpeakerEvent.types.startedSpeaking, users.mary, 5)
scheduleEvent(SpeakerEvent.types.stoppedSpeaking, users.mary, 15)
scheduleEvent(SpeakerEvent.types.startedSpeaking, users.john, 15)
scheduleEvent(SpeakerEvent.types.stoppedSpeaking, users.john, 45)
scheduleEvent(SpeakerEvent.types.startedSpeaking, users.mary, 45)
scheduleEvent(SpeakerEvent.types.stoppedSpeaking, users.mary, 60)
}, 1000)
console.log('Subscribing to the live events on the connection.')
// Subscribe to connection using connectionId.
// Multiple subscriptions to same connectionId are allowed. It can be useful to get the updates at multiple clients.
sdk.subscribeToConnection(connectionId, (data) => {
// console.log(data);
const {type} = data
if (type === 'transcript_response') {
const {payload} = data
process.stdout.write('Live: ' + payload && payload.content + '\r')
// console.log('Live: ',payload && payload.content);
} else if (type === 'message_response') {
const {messages} = data
messages.forEach((message) => {
process.stdout.write('Message: ' + message.payload.content + '\n')
})
} else if (type === 'insight_response') {
const {insights} = data
insights.forEach((insight) => {
process.stdout.write(
`Insight: ${insight.type} - ${insight.text} \n\n`,
)
})
}
})
// Scheduling stop endpoint call after 60 seconds
setTimeout(async () => {
console.log('Stopping the connection')
try {
await sdk.stopEndpoint({
connectionId: connection.connectionId,
})
console.log('Connection stopped.')
console.log('Summary Info:', connection.summaryInfo)
console.log('Conversation ID:', connection.conversationId)
} catch (err) {}
}, 62 * 1000)
} catch (e) {}
})()