Recording Transcription to SMS

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!

You can read the guide below, or use our recipe to quickly copy the code!

Configuring the Code

This script is short and simple. There is only one route in this application which we will call /message.

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 that's 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.

@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 = '')

    # 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,
    return transcription_text

Running the application

You will need the Flask framework and the SignalWire Python SDK downloaded.

To run the application, execute export then run flask run.

Did this page help you?