I’m using Twilio Studio and their Voice Intelligence feature so I can have users call a number, they enter their meeting code (for our tracking), and then it will record their meeting. Twilio has it after the record it automatically gets transcribed and summarized. After voice intelligence is done I get a response to a webhook.
The part where I’m stuck is that I want to return the meeting code with the webhook response. I get the transcript looks something like this for the POST:
{
"account_sid": "AC803xxxxxxxx",
"service_sid": "GAexxxxxxxxxx",
"transcript_sid": "GTbxxxxxxxxxxxxx",
"customer_key": "",
"event_type": "voice_intelligence_transcript_available"
}
I want something like this ideally:
{
"account_sid": "AC803xxxxxxxx",
"service_sid": "GAexxxxxxxxxx",
"transcript_sid": "GTbxxxxxxxxxxxxx",
"customer_key": "",
"event_type": "voice_intelligence_transcript_available"
"meeting_code": "123456"
}
Or assign that meeting_code to a query parameter would be fine I just want to pass that value back. Can I do this in studio or do I need custom logic in. Function widget to assign the meeting_code?
Can I do that or should I assign it to a query parameter like below: const VoiceResponse = require('twilio').twiml.VoiceResponse;
exports.handler = async function (context, event, callback) {
console.log("in the func -- event", JSON.stringify(event));
console.log("in the func -- context", JSON.stringify(context));
let meeting_code = event.meeting_code; // Ex: 123456
try {
const response = new VoiceResponse();
response.record({
timeout: 60,
transcribe: true,
finishOnKey: "#",
playBeep: true,
maxLength: 14400, // 4 hours
trim: "do-not-trim",
transcribeCallback: `/dev/notification/callback?meeting_code=${event.meeting_code}`
});
return callback(null, response);
} catch (error) {
console.error("Error:", error);
return callback(error);
}
};
I’m using Twilio Studio and their Voice Intelligence feature so I can have users call a number, they enter their meeting code (for our tracking), and then it will record their meeting. Twilio has it after the record it automatically gets transcribed and summarized. After voice intelligence is done I get a response to a webhook.
The part where I’m stuck is that I want to return the meeting code with the webhook response. I get the transcript looks something like this for the POST:
{
"account_sid": "AC803xxxxxxxx",
"service_sid": "GAexxxxxxxxxx",
"transcript_sid": "GTbxxxxxxxxxxxxx",
"customer_key": "",
"event_type": "voice_intelligence_transcript_available"
}
I want something like this ideally:
{
"account_sid": "AC803xxxxxxxx",
"service_sid": "GAexxxxxxxxxx",
"transcript_sid": "GTbxxxxxxxxxxxxx",
"customer_key": "",
"event_type": "voice_intelligence_transcript_available"
"meeting_code": "123456"
}
Or assign that meeting_code to a query parameter would be fine I just want to pass that value back. Can I do this in studio or do I need custom logic in. Function widget to assign the meeting_code?
Can I do that or should I assign it to a query parameter like below: const VoiceResponse = require('twilio').twiml.VoiceResponse;
exports.handler = async function (context, event, callback) {
console.log("in the func -- event", JSON.stringify(event));
console.log("in the func -- context", JSON.stringify(context));
let meeting_code = event.meeting_code; // Ex: 123456
try {
const response = new VoiceResponse();
response.record({
timeout: 60,
transcribe: true,
finishOnKey: "#",
playBeep: true,
maxLength: 14400, // 4 hours
trim: "do-not-trim",
transcribeCallback: `https://api.mywebsite/dev/notification/callback?meeting_code=${event.meeting_code}`
});
return callback(null, response);
} catch (error) {
console.error("Error:", error);
return callback(error);
}
};
Share
Improve this question
edited Mar 21 at 10:09
DarkBee
15.5k8 gold badges72 silver badges117 bronze badges
asked Mar 18 at 16:20
CleverlyDoneCleverlyDone
791 silver badge14 bronze badges
2 Answers
Reset to default 1Inside twiml (Twilio Markup language) When you start a bidirectional stream or a unidirectional stream, after the stream tags you can send the parameter tag
<stream><Parameter name="to_number" value="{to_number}" /></stream>
Something like this and then you can fetch this inside data received from websocket only at the time of event being as start where you would have customParameters key in that data received
I eventually figured out the best way to my question leveraging my own back end to set the customer key.
So I realized that the transcribe and transcribeCallback do not correlate to the voice intelligence transcription. For the callback I ended up creating a POST request with the url query parameters to have the meeting code and other pertinent data.
Does it break best practice for api design?
Yes.
But does it work?
Also Yes.
const twilio = require('twilio');
exports.handler = async function (context, event, callback) {
let recordingCallback = `https://api.mycompany.us/dev/notification/callback?MeetingCode=${event.meeting_code}&OtherData=${event.other_data}`;
try {
const response = new twilio.twiml.VoiceResponse();
response.record({
timeout: 60,
finishOnKey: "#",
playBeep: true,
maxLength: 14400, // 4 hours
trim: "do-not-trim",
method: 'POST',
action: recordingCallback,
});
return callback(null, response);
} catch (error) {
console.error("Error:", error);
return callback(error);
}
};
After I receive the request I get the query parameters and then you can assign the with some business logic like the code below. I assign the customer key to the meeting_code
async function createTranscript() {
await client.intelligence.v2.transcripts.create({
channel: {
media_properties: {
source_sid: source_sid,
},
participants: [
{
user_id: "id1",
channel_participant: 1,
full_name: "Presenter",
role: "Customer",
},
{
email: "[email protected]",
user_id: "id2",
channel_participant: 2,
full_name: "Robot",
role: "Agent",
},
],
customer_key: meeting_code, // 123456
},
serviceSid: service_sid,
});
}
createTranscript();
It would return something like this:
{
"account_sid": "AC803xxxxxxxx",
"service_sid": "GAexxxxxxxxxx",
"transcript_sid": "GTbxxxxxxxxxxxxx",
"customer_key": "123456",
"event_type": "voice_intelligence_transcript_available"
}