Did you know you can capture real-time action items from conversations with customers, automatically push these items to a customer database, and never have to worry about missing another important task or feverishly scribble customer notes?
We will show you how to connect the Symbl voice API to Twilio Media Streams to access real-time raw audio and easily generate actionable insights and tasks from these audio streams. Take this workflow automation one step further—connect the Salesforce Opportunities dashboard to Twilio Flex to automatically send these valuable insights and tasks to the Salesforce CRM platform.
This blog post will guide you step-by-step through the workflow
Requirements
Before we can get started, you’ll need to make sure to have:
To start, you’ll need to configure Twilio Media Streams and a Symbl Websocket server. If you haven’t already done so, refer to this blog post first to set up your environment.
Getting Started
At this point, you should be able to stream audio through your Websocket server into Twilio Flex and generate insights.
In order to take those generated insights and push them to your Salesforce dashboard in real-time, we will start by updating the `index.js` file in your Websocket server.
const WebSocket = require("ws");const express = require("express");const app = express();const server = require("http").createServer(app);const ws = new WebSocket.Server({ server });const WebSocketClient = require("websocket").client;const wsc = new WebSocketClient();const request = require('request');let connection = undefined;let client_connection = undefined;let opportunity_id = undefined;// Handle Web Socket Failuresws.on('connectFailed', (e) => {console.error('Connection Failed.', e);});// Handle Web Socket Connectionws.on("connection", (conn) => {connection = conn;connection.on('close', () => {console.log('WebSocket closed.')});connection.on('error', (erdr) => {console.log('WebSocket error.', err)});connection.on('message', (data) => {const msg = JSON.parse(data);if(data.type === 'utf8'){const {utf8Data} = data;}switch (msg.event) {case 'connected':console.log(`A new call has connected.`);break;case "start":console.log(`Starting Media Stream ${msg.streamSid}`);request.post({'auth': {'bearer': ''},method: 'POST',url: 'https:///services/data/v39.0/sobjects/Opportunity',body: { // Configure the payload as per your needs"Name": "Prospective Meeting with Magpie","CloseDate": "2020-04-12","StageName": "Prospecting"},json: true}, (err, response, body) => {opportunity_id = body.id;});break;......}}
In the code sample above, we are modifying the connection start
block with a POST
request that creates a new opportunity in your Salesforce dashboard with the provided json
payload. You can configure this payload as needed.
- Once the request is successful, we want to save the
opportunity id
in a variable so that we can use it to push action items next. (Note: To get your Salesforce Authentication Token, refer to this guide.) - Next, when action items are detected, we want to capture those insights and add them to our Salesforce dashboard under the opportunity we created.
Next, when action items are detected, we want to capture those insights and add them to our Salesforce dashboard under the opportunity we created.
To do this, we will modify the client_connection.on('message')
handler.
{......wsc.on("connect", (conn) => {client_connection = conn;......if(data.type === 'utf8'){const {utf8Data} = data;data = JSON.parse(utf8Data)console.log(data, "typeIS: " + data.type);if(data.type == "action_insights"){request.post({'auth': {'bearer': ''},method: 'POST',url: 'https:///services/data/v39.0/sobjects/Task',body: {"Subject": data.title,"Status": "Not Started","WhatId": opportunity_id,"Priority": "high","Description": data.description},json: true}, (err, response, body) => {console.log('request', body);});}}});
And that’s it! With this integration, your Salesforce dashboard should now have opportunities dynamically created from yours calls and all action items generated will be logged as tasks within the opportunity. If we head over to Salesforce, we can see an opportunity was created: Perspective Meeting with Magpie
Description
field. Read about the different Salesforce APIs.