# Building a Conversational AI Experience in Microsoft Teams using Power Automate and Microsoft Foundry

Modern enterprises want AI embedded directly into everyday collaboration tools. One of the most effective places to integrate AI is Microsoft Teams.  
This blog walks through a hands-on demo from an enterprise training program that demonstrates how to connect **Microsoft Teams, Power Automate, and Microsoft Foundry (earlier called Azure Ai Foundry)** to create a conversational AI experience without building a custom bot.

---

## Overview

**Demo Name**  
Teams → AI Response via Power Automate → Teams Reply

**What this demo demonstrates**  
A user types a natural language command in Microsoft Teams (for example, `/ai summarize this`). A Power Automate flow detects the command, invokes an Azure AI Foundry Prompt Flow, and posts the AI-generated response back into the same Teams conversation thread.

**Key takeaway**  
Microsoft Teams can be transformed into an AI interaction layer using low-code automation and enterprise AI services.

---

## End-to-End Flow

1. User posts `/ai <query>` in Microsoft Teams
    
2. Power Automate trigger fires
    
3. Flow checks if the message starts with `/ai`
    
4. Flow calls Azure AI Foundry Prompt Flow
    
5. AI generates a response
    
6. Power Automate posts the response back to the same Teams thread
    

---

## Architecture

Microsoft Teams  
↓  
Power Automate (Trigger + Logic)  
↓  
Azure AI Foundry Prompt Flow (Chat API)  
↓  
Power Automate  
↓  
Microsoft Teams (Reply)

---

## Step-by-Step Implementation

### Step 1: Create an Azure AI Foundry Resource

1. Go to the Azure portal
    
2. Create a Microsoft AI Foundry resource
    
3. Choose subscription, region, and resource group
    
4. Create an AI Foundry Hub
    

---

### Step 2: Create a Project

1. Open the AI Foundry portal
    
2. Create a new Project under the Hub
    
3. Verify project permissions
    

---

### Step 3: Deploy a Model

1. Open the Model catalog
    
2. Select a GPT model
    
3. Deploy the model and note the deployment name
    

---

### Step 4: Create a Prompt Flow

1. Go to Prompt Flows
    
2. Create a new Standard Flow
    
3. Add inputs and outputs:
    
    * Input: `userMessage` (string)
        
    * Output: `${llm.output}`
        
4. Configure the LLM tool:
    
    * API: Chat
        
    * Deployment name: Deployed GPT model
        
    * Temperature: 0.7
        
    * Response format: `{ "type": "text" }`
        

**Prompt Template**

```xml
system:
You are an enterprise assistant. Respond clearly and concisely.

user:
{{userMessage}}
```

5. Test the Prompt Flow
    

---

### Step 5: Deploy the Prompt Flow

1. Select Deploy
    
2. Choose Online endpoint
    
3. Wait for deployment to succeed
    
4. Copy the following values:
    
    * Target URI (ends with `/score`)
        
    * Deployment API Key
        

This endpoint will be used by Power Automate.

---

## Prerequisites Checklist

Before configuring Power Automate, ensure:

* AI Foundry Hub is created
    
* Project is created
    
* Prompt Flow is created and tested
    
* Prompt Flow uses the Chat API
    
* Input parameter `userMessage` exists
    
* Prompt Flow is deployed as an Online endpoint
    
* Deployment state is Succeeded
    
* Target URI and API key are available
    

---

## Power Automate Configuration

### Step 6: Create the Power Automate Flow

1. Go to Power Automate
    
2. Select Create → Automated cloud flow
    
3. Flow name: `Teams-AI-Foundry-Demo`
    
4. Trigger: When a new message is added to a chat or channel
    

---

### Step 7: Get Message Text from Teams

Add action:

Configure:

* Message ID from trigger
    
* Message type: Channel
    
* Team and Channel from trigger
    

---

### Step 8: Extract Plain Text

Add a Compose action with the following expression:

```xml
body('Get_message_details')?['body']?['plainTextContent']
```

Example output:

```xml
/ai What is Azure AI Foundry?
```

---

### Step 9: Check if Message Is an AI Command

Add a Condition action:

```xml
startsWith(outputs('Compose'), '/ai')
```

Proceed only if the condition evaluates to true.

---

### Step 10: Call Azure AI Foundry Prompt Flow

Add an HTTP action:

* Method: POST
    
* URI: `<Prompt Flow Target URI>/score`
    
* Headers:
    
    * Content-Type: application/json
        
    * Authorization: Bearer `<DEPLOYMENT_API_KEY>`
        

**Body**

```xml
{
  "userMessage": "@{trim(replace(outputs('Compose'), '/ai', ''))}"
}
```

---

### Step 11: Parse the AI Response

Add a Parse JSON action using this schema:

```xml
{
  "type": "object",
  "properties": {
    "output": {
      "type": "string"
    }
  }
}
```

---

### Step 12: Reply Back to Teams

Add action:

* Microsoft Teams – Reply with a message in a channel
    

Configure:

* Reply to message ID from trigger
    
* Message:
    

```xml
AI Response:
@{body('Parse_JSON')?['output']}
```

---

## Testing the Demo

In Microsoft Teams, post:

```xml
/ai What is Azure AI Foundry?
```

**Expected outcome**

* Power Automate flow runs successfully
    
* Prompt Flow is invoked
    
* AI response is posted in the same Teams conversation thread
    

---

## Why This Approach Works Well for Enterprises

* No custom bot framework required
    
* Low-code and easy to maintain
    
* Secure, Azure-native AI integration
    
* Easily extensible for summarization, RAG, HR, IT support, or internal assistants
