Build a conversational SMS bot with Azure Communication Services and Azure OpenAI
It is no secret that large language models (LLM) like ChatGPT have been all the rage in the last couple of months. These conversational models offer seamless and intuitive interfaces for users to interact with, enabling them to easily ask questions or carry out tasks. The Azure Communication Services team strives to provide developers with the tools to integrate these conversational entities with communication channels, and delight end users with exceptional support. In this blog we will show you how to use Azure Communication Services SMS capability and Azure OpenAI Service’s GPT-3 model to light up a personalized end user interaction scenario.
In today's blog, we are building an Obi Wan Kanobi conversational bot powered by Azure OpenAI and Azure Communication Services SMS. See the preview:
To follow along, you will need:
- An Azure account with an active subscription. Create an account for free .
- An active Communication Services resource and connection string. Create a Communication Services resource.
- An SMS-enabled telephone number. Get a phone number.
- Enable Event Grid resource provided on your subscription. See instructions.
- Create an Azure OpenAI resource. See instructions.
- Deploy an Azure OpenAI model. See instructions.
You can find the finished code for this blog on GitHub.
This application will leverage Azure Event Grid to listen for incoming text messages to Azure Communication Services number and an Azure Function to process the event and respond with an Azure OpenAI generated response.
We will start by configuring an Azure Function to receive Azure Event Grid events. To create the Azure Function, you can follow instructions to set it up directly on Visual Studio Code. (Ensure for the Azure Function to be of type EventGridTrigger). In this blog, we will jump ahead and show the configured Azure Function.
Next, we will add a call to Azure OpenAI to ask our model to generate a response. We will use REST APIs to POST a request with our prompt. For the prompt, we will use a combination of the message sent by the user and a pre-designed text. In this example, we want the GPT-3 model to act like Obi Wan Kenobi. We added some sample quotes for the model to draw inspiration from. These quotes help guide the model’s response and provide a more intuitive and conversational flow for the users.
We concatenate the prompt with the user’s message.
Finally, we will configure our SMS Client to respond with the new response generated by Azure OpenAI. You will need Azure Communication Services connection string to initialize the SMS Client. You can either paste the connection string directly in the code or place it inside your local.settings.json file in your Azure Function directory under values.
Then we will modify the function itself to add our SMS client logic.
To run the function locally, simply press F5 in Visual Studio Code. We will use ngrok to hook our locally running Azure Function with Azure Event Grid. You will need to download ngrok for your environment. Once the function is running, we will configure ngrok.
Copy the ngrok link provided where your function is running.
Finally, we configure SMS events through Event Grid in your Azure Communication Services resource. We will do this using the Azure CLI . You will need the Azure Communication Services resource ID found in the Azure Portal. (The resource ID will look something like: /subscriptions/<<AZURE SUBSCRIPTION ID>>/resourceGroups/<<RESOURCE GROUP NAME>>/providers/Microsoft.Communication/CommunicationServices/<<RESOURCE NAME>>)
Now that everything is hooked up, test the flow by sending an SMS to the phone number in the Azure Communication Services resource.
Published on:
Learn moreRelated posts
Coding at the Speed of Innovation: AI and more with Azure SQL Database
The Azure SQL Database team is all set to unveil new product announcements as Build 2024 approaches. Innovation is the prominent theme this ti...
Generate insights from audio and video data using Speech analytics in Azure AI Studio
In this video, we explore the power of speech analytics in Azure AI Studio to extract insights from audio and video data. This technology help...
Azure Custom Policy- PostgreSQL Product - Compliance Report not Available- New Feature Request
If you're attempting to create custom policies for Azure Cosmos DB for PostgreSQL at the subscription level and are running into issues where ...
Microsoft Causes Fuss Around Azure MFA Announcement
Microsoft's recent announcement regarding the requirement of Azure MFA for connections to services starting in July 2024 has caused quite a st...
PostgreSQL for your AI app's backend | Azure Database for PostgreSQL Flexible Server
If you want to use Postgres as a managed service on Azure and build generative AI apps, then the Azure Database for Postgres Flexible Server i...
Storage migration: Combine Azure Storage Mover and Azure Data Box
If you are looking to migrate your data from on-premises to Azure Storage, it can be challenging, but with Microsoft's solutions, you can make...
Loop DDoS Attacks: Understanding the Threat and Azure's Defense
This article provides a comprehensive overview of Loop DDoS attacks, a sophisticated and evolving cybersecurity threat that exploits applicati...
Azure Communication Services at Microsoft Build 2024
Join us for Microsoft Build 2024, either in-person in Seattle or virtually, to learn about the latest updates from Azure Communication Service...
Azure Developer CLI (azd) – May 2024 Release
The Azure Developer CLI (`azd`) has received a May 2024 update, version 1.9.0, making it simpler for developers to create, manage, and deploy ...
Join us at Build 2024: Get the latest on Azure Cosmos DB in Seattle or online!
Join Microsoft Build 2024 to get a sneak peek into the future of AI and data innovation. Taking place in Seattle and online from May 21 to 23,...