At Plivo, we’ve been brainstorming about how ChatGPT, OpenAI’s AI-adjacent natural language processing tool, might help our customers. Our cloud communications platform provides APIs that let businesses automate sending and receiving text messages, as well as voice calls. The first step toward figuring out how ChatGPT could elevate those tasks has been to try it ourselves. We wrote this post to help other organizations get started more quickly.
Your application and ChatGPT can interact in two ways — think of them as “to” and “from.” An application action (in Plivo’s case an incoming call or text message, for instance) could be a trigger to invoke ChatGPT. For instance, someone might text a question to a given phone number designated to communicate with ChatGPT, or tagged with an #askChatGPT hashtag. We could then use OpenAI APIs to pass that query to ChatGPT and return the answer to the person who initiated the query.
Another use case, for data going in the other direction, would have someone invoke something from ChatGPT that triggers an action in a third-party application. For instance, you could go to the OpenAI’s
Unfortunately, that second use case isn’t ready yet. Any application that wants to allow ChatGPT to use its APIs has to write an
Still, calling ChatGPT from your service’s APIs can accomplish some pretty useful tasks.
To see how a Plivo action could trigger ChatGPT, Plivo CTO Mike Ricordeau wrote a short proof-of-concept program in Python, using the Flask framework. His sms_bot.py
code is
To test the application, you’ll need a few bits of information, starting with an OpenAI API key. If you don’t have one already, sign up for an OpenAI account, then click
If you want to use Plivo as your test application, you’ll also need Plivo credentials.
The last variable you’ll need is the name of an OpenAI model or engine. We used GPT-3.5-turbo.
Now, turn to the instructions in the GitHub project’s README file. Follow the instructions to install, configure, and run the application on a local machine.
Before you deploy the application, you must expose it as a public URL. To do that, we recommend using a secure tunneling application such as
Copy the forwarding address from ngrok, visit the Plivo console, and add a Plivo application. Specify the address, postpended with “/sms,” in the Message URL.
Next, click the phone number you rented and associate it with the application you just created. In the Application Type drop-down, choose XML Application, and under Plivo Application choose the name of the Plivo application you added.
Now the application should be live and available. You can try it by texting a question in the form of a message to the phone number you used.
What happens when you do that? The Plivo platform receives the message and POSTs it to the Message URL. Ngrok forwards it to the Python application running locally, which connects to OpenAI by using the APIs in the program and asks the question. OpenAI gives the answer. The Python application then returns a Message XML element that contains the response, which Plivo sends to the user’s phone number.
In our test setup the entire “transaction” took about four seconds from when we tapped Send to when we received a response.
This simple use case helped us understand how to use OpenAI APIs with Plivo. You can adapt what we did to your own use case. Let us know what you learn — we’re on Twitter @Plivo.