- product:messaging - language:python - language:nodejs - sdk:compatibility - sdk:relayrealtime3 - sdk:relayrealtime4 A guide to using transcription status callbacks to message the transcript of call recordings via SMS. import LangSwitchMessage from @site/docs/guides/_common/languageSwitcher.mdx; ## Overview This code snippet uses transcription status callbacks in order to send a transcription of the created recording via SMS. When a recording is created with transcription enabled and the transcription callback pointing to this script, a SignalWire client object will be created and used to send the message to the end destination cell phone. You can learn more about transcription status callbacks, all of the possible parameters you can learn, and how to set them up in our [status callback mega guide](/guides/signalwire-status-callbacks#transcription-status-callbacks)! Full code example: Transcription to SMS
python @app.route(/message, methods=[POST]) def message(): call_sid = request.form.get(CallSid) transcription_text = request.form.get(TranscriptionText) from_number = request.form.get(From) client = signalwire_client(ProjectID, AuthToken, signalwire_space_url = YOURSPACE.signalwire.com) m = client.messages.create( body=You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from_=+1xxxxxxxxxx, to=+1xxxxxxxxxx ) return transcription_text js const express = require(express); const { Messaging } = require(@signalwire/realtime-api); var app = express(); app.use(express.urlencoded()); app.listen(process.env.PORT || 3000, () => { console.log(Server running on port 3000); }); let project_id = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX; let access_token = PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; const client = new Messaging.Client({ project: project_id, token: access_token, }); app.post(/message, (req, res) => { console.log(req.body); let call_sid = req.body.CallSid; let transcription_text = req.body.TranscriptionText; let from_number = req.body.From; client.send({ body: You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from: +###########, to: +###########, }); return res.sendStatus(200); }); js import express from express; import { SignalWire } from @signalwire/realtime-api; var app = express(); app.use(express.urlencoded()); app.listen(process.env.PORT || 3000, () => { console.log(Server running on port 3000); }); let project_id = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX; let access_token = PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; const client = await SignalWire({ project: project_id, token: access_token, }); let messageClient = client.messaging; app.post(/message, async (req, res) => { console.log(req.body); let call_sid = req.body.CallSid; let transcription_text = req.body.TranscriptionText; let from_number = req.body.From; await messageClient.send({ body: You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from: +###########, to: +###########, }); return res.sendStatus(200); }); ## Python This script is short and simple. There is only one route in this application which we will call /message. ### What do I need to run this code? You will need the Flask framework and the SignalWire [Python SDK](/compatibility-api/sdks) downloaded. ### How to Run Snippet? To run the application, execute export FLASK_APP=your_file_name.py then run flask run. ### Code Walkthrough We need to use request.form.get(ParameterName) in order to gather the CallSid, TranscriptionText, and From number parameters and store them in their own variables. If you want to include more parameters either to print to console or include in the message, you can gather them using the same format here. We then create a SignalWire client object with our project details and authentication. All thats left there is to create a message object and send all of the necessary information within the Body with the To number being the end destination number and the From number being a SignalWire number. python @app.route(/message, methods=[POST]) def message(): # gather necessary paramters and store them in an accessible variable call_sid = request.form.get(CallSid) transcription_text = request.form.get(TranscriptionText) from_number = request.form.get(From) # create a client object connected to our account & project client = signalwire_client(ProjectID, AuthToken, signalwire_space_url = YOURSPACE.signalwire.com) # create a text message and the text with necessary parameters m = client.messages.create( body=You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from_=+1xxxxxxxxxx, to=+1xxxxxxxxxx ) return transcription_text ## Node.js ### What do I need to run this code? We will need the following libraries (click their names to get instructions on how to install them): - [Express](https://www.npmjs.com/package/express) - [SignalWire Realtime Client](https://www.npmjs.com/package/@signalwire/realtime-api) ### How to Run Snippet? If you save this code snippet in a file called recordingTranscriptionViaSMS.js, for example, you then need to run: node recordingTranscriptionViaSMS.js. ### Code Walkthrough #### Load the necessary libraries javascript const express = require(express); const { Messaging } = require(@signalwire/realtime-api); javascript import express from express; import { SignalWire } from @signalwire/realtime-api; #### Instantiate Express In this section we create and launch Express, to then have it listen for requests on port 3000. javascript var app = express(); app.use(express.urlencoded()); app.listen(3000, () => { console.log(Server running on port 3000); }); #### Set your SignalWire Credentials In order for us to connect to SignalWire later on in the code using the Rest Client we first need to make sure we update project_id and access_token. javascript let project_id = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX; let access_token = PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; #### Instantiate the SignalWire Client Since were just going to be sending messages, there is no need to specify the Relay context. javascript const client = new Messaging.Client({ project: project_id, token: access_token, }); javascript const client = await SignalWire({ project: project_id, token: access_token, }); let messageClient = client.messaging; #### Expose the /message endpoint Here we expose the /message endpoint, that will solely respond to POST requests, and outline the actions to take when one comes in. We gather the call_sid, transcription_text, and from_number from the request body. We then create a message with the body making use of the data gathered from the request, using FROM and TO numbers of our liking. javascript app.post(/message, (req, res, next) => { console.log(req.body); let call_sid = req.body.CallSid; let transcription_text = req.body.TranscriptionText; let from_number = req.body.From; client.send({ body: You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from: +###########, to: +###########, }); }); js app.post(/message, async (req, res) => { console.log(req.body); let call_sid = req.body.CallSid; let transcription_text = req.body.TranscriptionText; let from_number = req.body.From; await messageClient.send({ body: You have received a voicemail from the number + from_number + . The voicemail transcription is as follows: + transcription_text + and the Call SID is + call_sid, from: +###########, to: +###########, }); return res.sendStatus(200); }); ## Wrap up It is very simple to send a particular recordings transcription via SMS, and it doesnt take a lot of code to accomplish this functionality either! ## Sign Up Here If you would like to test this example out, [create a SignalWire account and Space](https://m.signalwire.com/signups/new?s=1). Please feel free to reach out to us on our [Community Slack](https://signalwire.community/) or create a Support ticket if you need guidance!