Contact Sales

All fields are required

SignalWire AI Gateway: Back-to-Back Functions | SignalWireAdvanced communications from the source. | SignalWire
Developers

SignalWire AI Gateway: Back-to-Back Functions

Fetch, decode, decrypt

Technical Success Manager

Nicholas Ahrendt

In this installment of SignalWire in Seconds, follow along to decipher a hidden message using back_to_back_functions, an integral feature of SignalWire’s AI Gateway (SWAIG). SWAIG simplifies the connection between your AI voice agent and backend systems, allowing the AI to easily perform actions by integrating with databases or CRM software.

We’ll walk through how you can draft Fleming, an AI-powered digital employee, from three code segments: a RELAY v4 messaging application, a simple script written in SignalWire Markup Language (SWML), and a basic Node.js webserver. When combined, Fleming will be capable of retrieving, decoding, and decrypting sensitive information, encrypted with an Openssl AES-256-CBC cipher and hidden in a CSV file.

To see how Fleming works, check out the video walkthrough below.


RELAY v4 Messaging Application

Start by creating a short messaging application for receiving and responding to incoming SMS. The RELAY v4 Realtime SDK speeds up development of communication applications by integrating multiple telecom features into a single client architecture.

When accessing the Messaging namespace of the Realtime client, your application can listen for events like onMessageReceived. These events are triggered when an incoming SMS or MMS is received on a specified topic.

Messaging Client Example

The application will collect sensitive information from end users and store the data in a CSV file that Secret AI Agent Fleming will use later on. Users will be asked to submit the code_name of their intended target, and the secret_message they wish to convey.

To aid in the decryption process, users must also provide the key and Initialization Vector (iv) they used to encrypt their message. The response body of each reply will be stored in the CSV document.

The full RELAY v4 script is available here.

Fleming’s SWML Script and Decryption Server

Programmable Unified Communications (PUC) helps execute the SWML script and run the decryption server, which together define Fleming’s advanced personality and ability to decrypt complex ciphers.

SWAIG’s back_to_back_functions allow SignalWire’s AI Agents to call one function immediately after another. This makes it easy to pass important data from one function to the next, streamlining your SWML script and improving the performance of your digital employee.

Three main functions will define the virtual agent’s skill set: fetch, decode, and decrypt. With each successive step, Fleming will perform the function specified in the prompt’s instructions.

Fetching the Classified Information

The first step is to equip your AI Agent with the tools to retrieve the classifiedInfo stored in your CSV document. This is where the arguments come into play: an argument is a JSON object that defines the input for the function. Once received, an argument is processed by the Data Map to perform an action or return a response.

Fetch SWAIG Function


/fetch Server Endpoint

In this scenario, the argument Fleming aims to pass along is a code_name given by the caller. When directed, he will navigate to your server’s /fetch endpoint, identified by the webhook URL in the function’s Data Map.

At this endpoint, the code_name is used to search the CSV document created earlier. The goal is to find a Base64 encoded and encrypted secret_message, along with the 256-bit key used to encrypt it, and the 16-byte iv used for encryption randomness.

Once the classifiedInfo is collected, it is returned to the AI Agent’s knowledge via the response of the data_map’s output. Here, back_to_back_functions appears alongside the response as an action object. Setting this property to true allows Fleming to execute the second function, decode, with the fetched results.

Decoding the Secret Message

The decode SWAIG function works similarly to fetch, taking the secret_message retrieved from the server as its argument. This process results in a decoded_message, providing a crucial piece of the decryption puzzle.

Decode SWAIG Function


/decode Server Endpoint

The next big change in the process involves toggle_functions. This ensures that Fleming doesn’t jump from retrieving the classified info to decrypting it without first obtaining the decoded_message. This step is crucial because the decryption process on the server would fail without it.

Decrypting the Decoded Message

Fleming’s SWML script concludes in the third SWAIG function: decrypt. To reinforce the toggle_functions sequence, set the activity parameter to false.

Decrypt SWAIG Function


/decrypt Server Endpoint

Using the information gathered during the conversation with the caller, your digital employee will send the server’s decryption endpoint a payload including the decoded_message, key, and iv. The server will return a JavaScript expression with the fully decrypted_message, which Fleming will share with the caller.

You can find the full SWML script here and the full full Node.js server script here.

Configuring Your Phone Number

Before deploying Fleming’s SWML script and your RELAY v4 messaging application, associate them with a SignalWire phone number. Using the When a Call Comes In dropdown, select your agent. Under the Messaging Settings, select RELAY Application from the Handle Messages Using dropdown. Using the RELAY Topic field, type in the topic you chose when developing your RELAY v4 client. Finally, save your phone number settings and test out your new operative by calling the selected number.

Test Data

Code Name: <Your-Choice>
Secret Message: “Welcome to SignalWire in Seconds” | payIZgzSKI8xKL/TXzkEmznxbV5Bcca5ermVauarKkDXszqgjEtkKuszVdw3Vj/i
Key: 9809dfbb2026dc5eba581451174db58d1a34a567ded81778f594e3c99215cd96
IV: 1082e827f6ba8e473ae05809e40a3580

Design your own digital employee from the ground up by exploring our developer docs for even more in-depth technical documentation and bring any questions to our developer community on Slack. We're excited to see what you build!

Related Articles