# Quickstart - Get chats and send message

> The purpose of this guide is to help you create a working sample that uses different Microsoft Teams activities, including the [Get Chats](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chats#get-chats), [Get Chat Members](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chat-members#get-chat-members), [Send Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-send-message#send-message) and [Get Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-message#get-message) activities.

## Overview

The purpose of this guide is to help you create a working sample that uses different Microsoft Teams activities, including the [Get Chats](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chats#get-chats), [Get Chat Members](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chat-members#get-chat-members), [Send Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-send-message#send-message) and [Get Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-message#get-message) activities.

This working sample enables you to quickly verify the connection to your [registered](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-setup#setup) Microsoft Teams application and get familiar with the activity's input/output datatypes.

After completing the steps in this guide, you'll have an automation sequence that does the following:

1. Establishes a connection to your registered Microsoft Teams application ([Microsoft Teams Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-scope#microsoft-teams-scope)).
2. Retrieves all of your chats ([Get Chats](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chats#get-chats)).
3. Retrieves the members of each of your chats ([For Each](https://docs.uipath.com/activities/docs/for-each) and [Get Chat Members](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chat-members#get-chat-members)).
4. Locates the chat that includes a specific chat member and sends a message ([If](https://docs.uipath.com/activities/docs/if), [Assign](https://docs.uipath.com/studio/docs/the-assign-activity), and [Send Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-send-message#send-message).
5. Verifies the message was sent successfully by retrieving and outputting the message Id and message content [Get Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-message#get-message) and [Write Line](https://docs.uipath.com/activities/docs/write-line)).

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-35334-94de3d1f-ee0b4767.webp)

## Prerequisites

Before you begin:

1. Complete the Microsoft Teams [Setup](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-setup#setup) steps.
2. Create or use an existing chat, send at least one chat message.

## Steps

### Build your project

1. Add the [Microsoft Teams Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-scope#microsoft-teams-scope) activity to your project.
2. Enter the **ApplicationId** for your registered application.
   * For more information, see the [Register your application](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-setup#setup) section in **Setup** guide.
3. From the **AuthenticationType** drop-down list, select the applicable authentication flow (e.g., *InteractiveToken*).
   * For more information, see the [Unattended vs. Attended Automation](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-scope#microsoft-teams-scope) in the **Microsoft Teams Scope** activity page.
4. Add the [Get Chats](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chats#get-chats) activity after the **Microsoft Teams Scope** activity.
   1. Create and enter a `Chat[]` variable for your **Chats** value (e.g., *myChats*).
      * When creating your variable, select *Microsoft.Graph.Chat* as the variable type.
   2. Add a [For Each](https://docs.uipath.com/activities/docs/for-each) activity after the **Get Chats** activity.
   3. In the **TypeArgument** property, select *Microsoft.Graph.Chat*.
   4. In the **Values** property, enter the `Chat[]` variable you created for the **Get Chats** activity (e.g., *myChats*).
5. In the **For Each** activity, add an [Assign](https://docs.uipath.com/studio/docs/the-assign-activity).
   1. Create and enter a `String` variable for the **To** property (e.g., *chatId*)
   2. In **Value** property, enter *item.Id*.
      * Creating and assigning the *item.id* value to this variable enables it to be used in a later **For Each** activity that has a different argument type.
   3. Add the [Get Chat Members](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-chat-members#get-chat-members) activity after the **Assign** activity.
   4. In the **ChatId** property, enter *Item.Id* to get the members for each chat.
   5. Create and enter a `ConversationMember[]` variable for your **ChatMembers** value (e.g., *myChatMembers*).
      * When creating your variable, select *Microsoft.Graph.ConversationMember* as the variable type.
   6. Add another **For Each** activity after the **Get Chat Members** activity.
   7. In the **TypeArgument** property, select *Microsoft.Graph.ConversationMember*.
   8. In the **Values** property, enter the `ConversationMember[]` variable you created for the **Get Chat Members** activity (e.g., *myChatMembers*).
6. In the **For Each** activity, add an [If](https://docs.uipath.com/activities/docs/if) activity.
   1. In the **Condition** property, enter a value to identify a specific chat by member (e.g., *item.DisplayName="Sarah Connor"*)
7. In the **Then** sequence block, add the [Send Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-send-message#send-message) activity.
   1. In the **ChatId** property, enter the `String` variable you created for the **Assign** activity (e.g., *chatId*).
   2. Enter your **Body** content that you want to send (e.g., *"Just saying hi"*)
   3. In the **BodyType** property, enter *BodyType.Text*.
   4. Create and enter a new `String` variable for your **MessageId** value (e.g., *newMessageId*)

      ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-35060-c8063717-bb9086b1.webp)

### Test your project

1. To test that your activities retrieved your Chats, the Chat Members, and sent a Message, add a [Write Line](https://docs.uipath.com/activities/docs/write-line) activity after the **Send Message** activity.
   1. In the **Text** property, enter the `String` variable you created for the **Send Message** activity (e.g., *newMessageId*)
2. Add the [Get Message](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-get-message#get-message) activity after the **Write Line** activity.
   1. In the **ChatId** property, enter the `String` variable you created for the **Assign** activity (e.g., *chatId*).
   2. In the **MessageId** property, enter the `String` variable you created for the **Send Message** activity (e.g., *newMessageId*).

   3. Create and enter a `ChatMessage` variable for your **Message** value (e.g., *newMessage*).
      * When creating your variable, select _Microsoft.Graph.ChatMessage_as the variable type.
3. Add another **Write Line** activity after the **Get Message** activity.
4. In the **Text** property, enter the `ChatMessage` variable you created for the **Get Message** activity and append *.Body.Content* to the end of it (e.g. *newMessage.Body.Content*)
5. Click **Run** and verify the **Output** window includes your sent message Id and content.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-36057-fa5fc426-bce43dd6.webp)

You're done!

When you're ready, try the other [Quickstart](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-quickstarts) guides to get more familiar with the different Microsoft Teams activities.

To learn more about the Microsoft Teams activities (including example property inputs/outputs), see the following activity pages for a complete activity list and links to the activity detail pages.

* [Teams](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-teams-teams)
