--- title: "Microsoft Teams" slug: "microsoft-teams" updated: 2024-07-25T12:26:32Z published: 2024-07-25T12:26:32Z canonical: "docs.rocket.chat/microsoft-teams" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.rocket.chat/llms.txt > Use this file to discover all available pages before exploring further. # Microsoft Teams With the Microsoft Teams integration, you can: - Receive messages from Microsoft Teams (**Incoming WebHook**) - Send messages to Microsoft Teams Channel (**Outgoing WebHook**) ## Create incoming webhook in Rocket.Chat **Note:** It is recommended to create a New Team so that not all members in your organization have access to this integration. 1. **Create Incoming Webhook with Default parameters:** - Go to **Integrations** --> Create **New integration** --> Select **Incoming WebHook** - Assign **Name** - Assign **Post to Channel** (This will be the Channel where you want to receive msg from Teams) - Assign **Post as** (Create Bot user and add bot the above mentioned Channel) - Copy and paste below script in **Script** section > [!NOTE] > The number 16 in the following script (`request.content.text.slice(16)`) should be updated to `9 + MS Teams bot username length`. This command is used to remove the bot tag from the text received from MS Team so that only the message is displayed in Rocket.Chat (e.g. if the bot username in MS Teams is rocket.bot, which is 10 characters long, then 16 should be updated to 19 = 9 + 10). ```javascript class Script {    process_incoming_request({ request }) {        // UNCOMMENT THE BELOW LINE TO DEBUG IF NEEDED.        // console.log(request.content);        if ('edited_message' in request.content) {            request.content = request.content;        }        let from = request.content.from;        let who = from.name;        let icon_url = '/avatar/' + from.name + '.jpg'        let body = request.content.text.slice(16);        if(!body) {          if(request.content.hasOwnProperty("sticker") && request.content.sticker.emoji) {            // It's a sticker            body = request.content.sticker.emoji        } else {           return {}          }        } return { content: { username: who,                 icon_url: icon_url,                 text: body, }, response: { type: "message", attachments: [{ contentType: "application/vnd.microsoft.card.adaptive", content: { type: "AdaptiveCard", version: "1.4", body: [{ type: "TextBlock", text: "Message received", }], }, }], } };    } } ``` 1. **Save** and then open your **Incoming Webhook**. You should be able to see **Webhook URL** just **copy** that, we will need that during creating **Outgoing Webhook** in MS Teams. ## Create outgoing webhook in MS Teams: 1. Select the appropriate team and select **Manage team** from the (**•••**) drop-down menu. 2. Choose the **Apps** tab from the navigation bar. 3. From the window's lower right corner select **Create an outgoing webhook**. 4. In the resulting popup window complete the required fields: **Note :** The Name we mentioned above will be the bot name, so when you send messages to Rocket.Chat, mention the bot. For example, `@namebot`. - **Name** - The webhook title and @mention tap. (This will be your bot name in MS Teams) - **Callback URL** - Paste the URL here we copied from Rocket.Chat. - **Description** - A detailed string that will appear in the profile card and the team-level App dashboard. - **Profile Picture** (optional) an app icon for your webhook. - Select the **Create** button from lower right corner of the pop-up window and the outgoing webhook will be added to the current team's channels. ## Create incoming webhook in MS Teams: 1. Navigate to the **Team** where you want to add the webhook and select (**•••**) **More Options** from the top navigation bar and Select **Apps** and select **More apps**. - Choose **Connectors** from the drop-down menu and search for **Incoming Webhook**. - Select the **Configure** button, provide a name, and, optionally, upload an image avatar for your webhook. - Select appropriate **Teams** and **Channel**. - The dialog window will present a unique URL that will map to the channel. Make sure that you **copy and save the URL**—you will need to provide it to Rocket.Chat Outgoing WebHook. - Select the **Done** button. The webhook will be available in the team channel. ## Create outgoing webhook in Rocket.Chat: 1. Create **Outgoing Webhook** from Integration: - Select **Message Sent** as **Event Trigger** - Select the **Channel** (same as mentioned in Incoming Webhook) - Paste the **URL** we copied from Microsoft Teams - Select Bot **Post as** (same as in Incoming Webhook) - Paste Below **Script**: ```javascript class Script {        prepare_outgoing_request({ request }) {          console.log(request.data);            if (request.data.bot) {                //Don't repost messages from the bot.                return { };            } else {                return {                    url: request.url,                    method: 'POST',                    headers: {"ContentType":"application/json","Content-type":"application/json"},                    data: {                      context: 'http://schema.org/extensions',                      type: 'MessageCard',                    //  text: '{\'' + request.data.user_name+ ':': \"Isravel - Hello World\"}';                                  text: request.data.user_name.bold() + ": " + request.data.text,                      //                      text: encodeURIComponent( request.data.user_name.bold() + request.data.text)                    },                 //   method: 'GET'                };            }        }    } ```