Triggered by a Teams message – no custom connector required
Why Would You Do This?
Azure AI Foundry is great for building and hosting AI agents. But getting those agents to actually do something useful in the real world – responding to users, triggering workflows, sending replies – requires plumbing. Logic Apps is perfect for that plumbing.
In this post, I’ll show you how to build a Logic App that:
- Triggers when a message is posted to a specific Teams channel
- Sends that message to an Azure AI Foundry agent via its REST API
- Posts the agent’s response back to the same Teams thread
This is a great pattern for things like internal Q&A bots, helpdesk triage, or any scenario where you want an AI agent reachable directly from Teams – without building a full Copilot Studio agent.
What You’ll Need
Before you start, make sure you have the following in place:
- An Azure AI Foundry project with a deployed agent (we’ll grab the endpoint and key from here)
- A Logic App (Consumption plan is fine for this)
- A Teams channel you can post to – and permissions to add connectors to it
- A Microsoft 365 account connected to your Logic App (for the Teams connector)
Step 1: Get Your Agent’s Endpoint from Azure AI Foundry
First, grab the REST endpoint for your deployed agent. Head to Azure AI Foundry and open your project.
- Navigate to your AI Foundry project in the Azure portal
- Click on Agents in the left nav, and open the agent you want to call
- Click the </> API tab or look for the Endpoint section
- Copy the Endpoint URL and the API Key – you’ll need both shortly
The endpoint will look something like this:
https://<your-project>.openai.azure.com/openai/deployments/<agent-id>/chat/completions?api-version=2024-05-01-preview
Step 2: Create the Logic App
If you don’t have a Logic App yet, create one now:
- In the Azure portal, search for Logic Apps and click Create
- Choose Consumption (pay-per-execution) unless you have a reason for Standard
- Pick your resource group, region, and give it a sensible name – something like
la-teams-foundry-agent - Hit Review + Create and wait for deployment
Step 3: Add the Teams Trigger
Now open your Logic App in the designer and add the trigger.
- In the Logic App Designer, click Add a trigger
- Search for Microsoft Teams and select it
- Choose the trigger: When a new channel message is added
- Sign in with your Microsoft 365 account when prompted
- Select the Team and Channel you want to monitor
Step 4: Extract the Message Body
The Teams trigger gives you a lot of payload, but we only need the message text. Add a step to pull it out cleanly.
- Click + New step
- Search for and add a Compose action
- Set its Input to the dynamic value: Message body content from the trigger
The raw Teams message body comes through as HTML. You may want to add a second Compose step to strip the tags. Use this expression:
replace(replace(outputs('Compose'), '<p>', ''), '</p>', '')
For most agents, sending slightly messy HTML is fine and the model handles it gracefully – but stripping it gives you cleaner inputs.
Step 5: Call the Azure AI Foundry Agent via HTTP
This is the core step – an HTTP action that sends the user’s message to your Foundry agent and gets a response back.
- Add a new step and search for HTTP
- Select the HTTP action (not the HTTP + Swagger one)
- Configure it as follows:
| Field | Value |
|---|---|
Method |
POST |
URI |
Your Foundry agent endpoint URL (from Step 1) |
Headers - Content-Type |
application/json |
Headers - api-key |
Your API key (or Key Vault reference) |
Body |
See JSON below |
For the Body, use the following JSON – swap in the dynamic content from your Compose step for the user message:
{
"messages": [
{
"role": "user",
"content": "<output from your Compose step>"
}
],
"max_tokens": 800
}
api-key header with an Authentication block set to Managed Identity, and grant your Logic App’s managed identity the Cognitive Services OpenAI User role on your AI Foundry resource. Remove the api-key header entirely.Step 6: Parse the Agent’s Response
The HTTP action returns the full Azure OpenAI response payload. We need to parse it and extract just the assistant’s reply text.
- Add a Parse JSON action after the HTTP step
- Set Content to the Body of the HTTP response (dynamic content)
- Use this schema to map the response:
{
"type": "object",
"properties": {
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "object",
"properties": {
"content": { "type": "string" }
}
}
}
}
}
}
}
Once parsed, you can reference the agent’s reply in subsequent steps using this expression:
body('Parse_JSON')?['choices'][0]?['message']?['content']
Step 7: Post the Reply Back to Teams
Almost there. Now add the action to send the agent’s response back into the Teams thread.
- Add a new step and search for Microsoft Teams
- Select Post a reply to a message (V2) – this keeps the reply in the same thread
- Set the Team and Channel to match your trigger
- For Message ID, use the dynamic value: Message ID from the trigger – this threads the reply correctly
- For Message, use the parsed content expression from Step 6
<p> tags or add a bold prefix like <b>AI Assistant:</b> before the reply to make it clear the message is from your bot.Step 8: Save, Enable, and Test
- Make sure the Logic App is Enabled (check the top bar in the designer)
- Post a message in the Teams channel you configured
- Head to the Logic App’s Run History and watch the run appear
- Check each step – green ticks all the way down means you’re done
Within a few seconds of posting your Teams message, you should see the agent’s reply appear in the same thread. If you hit an error, the most common culprits are:
- 401 Unauthorized – double-check your API key or Managed Identity role assignment
- 400 Bad Request – usually a malformed JSON body; check your Compose expression output
- Teams trigger not firing – check the Logic App is enabled and the Teams connection is authenticated
Architecture Recap
Here’s the end-to-end flow you just built:
↓ Logic App Trigger – When a new channel message is added
↓ Compose – extract message text
↓ HTTP POST – call Azure AI Foundry agent endpoint
↓ Parse JSON – extract choices[0].message.content
↓ Teams – Post a reply to a message (threaded)
What to Do Next
This is a solid foundation – here’s where you can take it:
- Prevent reply loops – add a condition to ignore messages posted by your Logic App’s service account
- Add conversation history – store prior messages in an array variable and pass the full history in each API call for multi-turn conversations
- Add error handling – use a Scope action with a parallel branch to post a friendly failure message to Teams if the HTTP call fails
- Move to Managed Identity – remove the API key entirely and use role-based access
- Make it reusable – swap the Teams trigger for an HTTP Request trigger if you want to call this from other systems too
Wrapping Up
Logic Apps + Azure AI Foundry is a genuinely underrated combination. You get the flexibility of a fully custom AI agent without having to write or host any middleware code. The whole thing runs serverless, scales automatically, and the run history gives you excellent visibility into exactly what’s happening at each step.
If you’ve got questions or you’re hitting a specific error, drop a comment below – and if you found this useful, share it with your team.