Home > Back-end >  trigger chat bot from MS teams script
trigger chat bot from MS teams script

Time:03-30

I need to trigger some of the @ commands you get when typing in microsoft teams, but through a script. When typing in teams, you can type @General for example, and it will recognize it as a command. However, testing remotely with my powershell script, it gets pasted as plain text and not recognized. Need help getting this to work. Currently using the PSTeams module to paste a message. The message gets pasted to the teams channel just fine. It's just not recognizing the @ as a command in teams

I need to mention a chatbot, followed by a command to trigger it

import-module -Name PSTeams

$teamsID - 'longlinkurlwithlotsofstuff'

Send-TeamsMessage `
    -URI $teamsID `
    -MessageTitle 'Message Title' `
    -MessageText "@Genie whoisoncall" `
    -Color Chocolate

CodePudding user response:

Taking a look at the PSTeams module (hopefully I've found the one you are using) I don't think it handles mentions as the message body is being passed into the invoke-restmethod command 'as-is' in plaintext.

Looking at the Microsoft Graph API version of sending a Teams message, @mentions need to be passed in as an object itself with several properties, which suggests it is complex functionality. Highly recommend using MS Graph if you can as it opens up advanced options for message sending.

CodePudding user response:

You cannot do it through script.

You can achieve this using commandlist property in manifest file. In commandlist you have to mention commands that your bot can recommend to users.

"commandLists": [
                {
                    "scopes": [
                        "team",
                        "groupchat"
                    ],
                    "commands": [
                        {
                            "title": "Command 1",
                            "description": "Description of Command 1"
                        },
                        {
                            "title": "Command 2",
                            "description": "Description of Command 2"
                        }
                    ]
                },

Ref Doc: https://docs.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema#botscommandlists

  • Related