Loading...

Build a low code conversational SMS bot with Azure Communication Services and Azure OpenAI

Build a low code conversational SMS bot with Azure Communication Services and Azure OpenAI

In our last blog, we walked through the process of building an SMS conversational bot. Today we want to showcase a similar bot, but this time built completely on top of low code connectors for Power Automate. It is incredibly easy and exciting to leverage Azure Communication Services connectors in conjunction with Large Language Models (LLM) like ChatGPT to build a conversation bot. For this blog, we will be building Anton, a personal trainer bot for Contoso Gym. See the preview:

 

ddematheu_0-1677025513942.png

 

To follow along you will need:

 

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 Event Grid trigger for your Power Automate flow. This trigger will automatically connect to your existing Azure subscription and to the Azure Communication Services resource to configure your event subscription.

 

ddematheu_1-1677025657239.png

 

To keep the data organized, you will add a Parse JSON connector to help us parse the event. The event schema follows this structure:

 

Schema (click to see) { "properties": { "data": { "properties": { "From": { "type": "string" }, "Message": { "type": "string" }, "MessageId": { "type": "string" }, "ReceivedTimestamp": { "type": "string" }, "To": { "type": "string" } }, "type": "object" }, "dataVersion": { "type": "string" }, "eventTime": { "type": "string" }, "eventType": { "type": "string" }, "id": { "type": "string" }, "metadataVersion": { "type": "string" }, "subject": { "type": "string" }, "topic": { "type": "string" } }, "type": "object" }

 

Add that schema to the Parse JSON connector and add the event body as the content.

ddematheu_2-1677025761655.png

 

Next, we must add a call to Azure OpenAI to ask the 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 Anton, a personal trainer at Contoso Gym. We added some sample quotes from which the model can draw inspiration. These quotes help guide the model’s response and provide a more intuitive and conversational flow for the users. See the completed prompt below:

 

 

You're Anton Stanescu and you are a personal trainer at Contoso Gym. You are having a conversation with one of your students. You are trying to motivate them to work out. Examples of the types of things that Anton says: - The only bad workout is the one that didn't happen. - Strive for progress, not perfection. - You won't get the muscle without the dedication and the drive - Train hard...so you can stop a train if you need to. - Push up, push down, push up, push down - Exercise should be regarded as tribute to the heart. Anton: Welcome to the Contoso Gym! Big things await for you. Student:

 

 

To keep the flow organized, we will add a compose connector for our prompt so we can easily reference it later.

ddematheu_3-1677025812597.png

 

To communicate with the Azure OpenAI service, we will use POST request inside of an HTTP connector. In return, we will receive a text generated by the Azure OpenAI model. To configure the HTTP connector, you will need the URI to your Azure OpenAI resource. You will also need the `api-key` for your Azure OpenAI resource.

 

 

<base_url> + /openai/deployments/ + <deployment_name> + /completions?api-version=2022-12-01

 

 

ddematheu_4-1677025870598.png

 

Using the compose output for our prompt, we will concatenate together the prompt, the message the user sent through SMS, and a stop trigger for the Open AI model to stop generating text:

 

 

concat(outputs('Compose'), body('Parse_JSON')?['data']?['Message'], '\nAnton:')

 

 

Once we have the HTTP connector d, we will use a Parse JSON connector to process the response from Azure Open AI. The expected schema from Azure Open AI takes the following format:

 

Schema (click to see) { "properties": { "choices": { "items": { "properties": { "finish_reason": { "type": "string" }, "index": { "type": "integer" }, "logprobs": {}, "text": { "type": "string" } }, "required": [ "text", "index", "logprobs", "finish_reason" ], "type": "object" }, "type": "array" }, "created": { "type": "integer" }, "id": { "type": "string" }, "model": { "type": "string" }, "object": { "type": "string" } }, "type": "object" }

 

We will configure it to use the body of the http request as the content the schema above.

ddematheu_5-1677025928198.png

 

Finally, we will configure our SMS connector for Azure Communication Services to respond with the new response generated by Azure OpenAI. You will need a connection string for your Azure Communication Services resource to initialize the SMS connector.

 

ddematheu_7-1677025978170.png

 

Now that everything is connected, test the flow by sending an SMS from your phone to the phone number you acquired through the Azure Communication Services resource.

Congratulations! using Power Automate. Azure Communication Services provides out of the box connectors for SMS, Email and Chat. Whether it is having Anton, the personal trainer bot talk to your customers or having a real person interact with them, Azure Communication Services can help. To learn more about other resources that Azure Communication Services offers see the links below:

Published on:

Learn more
Azure Communication Services Blog
Azure Communication Services Blog

Azure Communication Services Blog articles

Share post:

Related posts

Transforming Field Operations with AI, Azure Maps & Dynamics 365

Efficient field operations are the backbone of successful, data-driven organizations. Yet, many businesses continue to struggle with scattered...

5 hours ago

Failures Happen in Cloud, but how Azure Cosmos DB keeps your Applications Online

The only thing that’s constant in distributed systems is failures. No cloud platform is immune to failures — from regional outages and transie...

1 day ago

The `azd` extension to configure GitHub Copilot coding agent integration with Azure

This post shares how to set up the GitHub Copilot coding agent integration with Azure resources and services by using the Azure Developer CLI ...

1 day ago

Announcing Azure MCP Server 1.0.0 Stable Release – A New Era for Agentic Workflows

Today marks a major milestone for agentic development on Azure: the stable release of the Azure MCP Server 1.0! The post Announcing Azure MCP ...

3 days ago

From Backup to Discovery: Veeam’s Search Engine Powered by Azure Cosmos DB

This article was co-authored by Zack Rossman, Staff Software Engineer, Veeam; Ashlie Martinez, Staff Software Engineer, Veeam; and James Nguye...

3 days ago

Azure SDK Release (October 2025)

Azure SDK releases every month. In this post, you'll find this month's highlights and release notes. The post Azure SDK Release (October 2025)...

4 days ago

Microsoft Copilot (Microsoft 365): [Copilot Extensibility] No-Code Publishing for Azure AI Foundry Agents to Microsoft 365 Copilot Agent Store

Developers can now publish Azure AI Foundry Agents directly to the Microsoft 365 Copilot Agent Store with a simplified, no-code experience. Pr...

5 days ago

Azure Marketplace and AppSource: A Unified AI Apps and Agents Marketplace

The Microsoft AI Apps and Agents Marketplace is set to transform how businesses discover, purchase, and deploy AI-powered solutions. This new ...

7 days ago

Episode 413 – Simplifying Azure Files with a new file share-centric management model

Welcome to Episode 413 of the Microsoft Cloud IT Pro Podcast. Microsoft has introduced a new file share-centric management model for Azure Fil...

9 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy