MicrosoftDocs / msteams-docs

Source for the Microsoft Teams developer platform documentation.
https://aka.ms/teamsdev
Creative Commons Attribution 4.0 International
280 stars 501 forks source link

Sending responses to extensions - documentation incomplete #8373

Open bandtank opened 1 year ago

bandtank commented 1 year ago

The documentation does not say how to respond to extension search or action requests. It is assumes the SDK will be used and the implementation details are hidden as a result.

Here is an incoming request from a search extension with a few fake values:

{
   "name":"composeExtension/query",
   "type":"invoke",
   "timestamp":"2023-03-26T18:01:09.825Z",
   "localTimestamp":"2023-03-26T12:01:09.825-06:00",
   "id":"f:11111111-1111-1111-1111-111111111111",
   "channelId":"msteams",
   "serviceUrl":"https://smba.trafficmanager.net/amer/",
   "from":{
      "id":"29:123",
      "name":"Bob Smith",
      "aadObjectId":"123"
   },
   "conversation":{
      "conversationType":"personal",
      "tenantId":"123",
      "id":"a:12345ABCDE"
   },
   "recipient":{
      "id":"28:222222222222-2222-2222-2222-222222222222",
      "name":"CometDev"
   },
   "entities":[
      {
         "locale":"en-US",
         "country":"US",
         "platform":"Mac",
         "timezone":"America/Denver",
         "type":"clientInfo"
      }
   ],
   "channelData":{
      "tenant":{
         "id":"123"
      },
      "source":{
         "name":"compose"
      }
   },
   "value":{
      "commandId":"info",
      "parameters":[
         {
            "name":"term",
            "value":"testaa"
         }
      ],
      "queryOptions":{
         "count":25,
         "skip":0
      }
   },
   "locale":"en-US",
   "localTimezone":"America/Denver"
}

Sending a response with the following attributes results in an error:

POST https://smba.trafficmanager.net/amer/v3/conversations/a:12345ABCDE/activities

{
  "composeExtension":{
     "type":"result",
     "attachmentLayout":"list",
     "attachments":[
        {
           "contentType":"application/vnd.microsoft.card.hero",
           "content":{
              "title":"Test0 Title",
              "text":"Test0 text"
           }
        },
        {
           "contentType":"application/vnd.microsoft.card.hero",
           "content":{
              "title":"Test1 Title",
              "text":"Test1 text"
           }
        }
     ]
  }
}

The error:

{
   "data":{
      "error":{
         "code":"BadSyntax",
         "message":"Activity must include non empty 'text' field or at least 1 attachment"
      }
   },
   "code":400
}

It seems like the problem is related to the /activities route. The documentation does not say which route to use or how to find it. This problem may also be related to the verb. I assume POST should be used, but I have encountered other errors when using the Teams APIs when POST was used instead of PUT, which the documentation did not specify.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

ghost commented 1 year ago

Hi bandtank! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

Prasad-MSFT commented 1 year ago

@bandtank - Could you please let us know which content you want us to update in this doc? Also please refer this and check if it helps: https://learn.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/search-commands/respond-to-search?tabs=dotnet

bandtank commented 1 year ago

Ideally, I think the endpoints should be added to at least the following places:

An example of what would be helpful to see in the first two bullet points is shown here.

bandtank commented 1 year ago

As an update, I have learned a few things that are not explained anywhere in the documentation. The message is sent as type invoke, but responding with a type invoke does not work, at least not to the endpoint I'm using. The JSON structure shown in the documentation starts with this:


{
  "composeExtension":{
     "type":"result",
     "attachmentLayout":"list",
     "attachments":[
     ...
     ]
  }
}

which seems to be wrong. It might need to look like this:

{
  "type":"result",
  "attachmentLayout":"list",
  "attachments":[
    ...
  ]
}

Type result does not appear to work. An error was returned saying Unknown activity type. If I send a response with type message, the results go in the personal chat (if the context is a personal chat), group chat, and so on. Getting the results to appear as list items in the message extension result area is not yet working. That's what I need documentation to achieve:

bandtank commented 1 year ago

I tried the types in this file without success. I'm out of ideas.

bandtank commented 1 year ago

I checked the browser debug console to see what is being sent. Here is an example:

{
  "name": "composeExtension/query",
  "value": {
    "commandId": "info",
    "parameters": [
      {
        "name": "term",
        "value": "sadfasdf"
      }
    ],
    "queryOptions": {
      "count": 25,
      "skip": 0
    }
  },
  "imdisplayname": redacted,
  "conversation": {
    "id": "19:2402b3bf-99b7-4979-9970-6ad9528a3ba7_2cf61cbd-a711-4f9f-95b4-92a7b20cb017@unq.gbl.spaces"
  }
}

This is what my bot received:

{
  "name": "composeExtension/query",
  "type": "invoke",
  "timestamp": "2023-03-31T03:49:00.907Z",
  "localTimestamp": "2023-03-30T21:49:00.907-06:00",
  "id": "f:1a1a8681-8e28-32df-3441-88a71477e5c1",
  "channelId": "msteams",
  "serviceUrl": "https://smba.trafficmanager.net/amer/",
  "from": {
    "id": "29:1kCq75A-g8wVc36XZqhI504r073ByA0Uk0KMcIAIWMvrm_2iivPfbNZ5mDObiz_gFfmkcf2hioAZO5NfG_mfiRw",
    "name": redacted,
    "aadObjectId": "2402b3bf-99b7-4979-9970-6ad9528a3ba7"
  },
  "conversation": {
    "conversationType": "personal",
    "tenantId": redacted,
    "id": "a:1HlPo9qAhR5bbfnkumzXUvpkO2yQ4z1lt89QIby3dqHrGLvfRHwnkoPmTOGjNqSGYTDzySM9jJbil18BJ7TOh27eedpe7_rpaHjjKBi62f3v4KaXZShqFtUetdPz2TZ7w"
  },
  "recipient": {
    "id": "28:2cf61cbd-a711-4f9f-95b4-92a7b20cb017",
    "name": "CometDev"
  },
  "entities": [
    {
      "locale": "en-US",
      "country": "US",
      "platform": "Web",
      "timezone": "America/Denver",
      "type": "clientInfo"
    }
  ],
  "channelData": {
    "tenant": {
      "id": redacted
    },
    "source": {
      "name": "compose"
    }
  },
  "value": {
    "commandId": "info",
    "parameters": [
      {
        "name": "term",
        "value": "sadfasdf"
      }
    ],
    "queryOptions": {
      "count": 25,
      "skip": 0
    }
  },
  "locale": "en-US",
  "localTimezone": "America/Denver"
}

Notice the conversation IDs are very different. Why is the bot receiving a different (probably wrong) conversation ID?

Prasad-MSFT commented 1 year ago

I checked the browser debug console to see what is being sent. Here is an example:

{
  "name": "composeExtension/query",
  "value": {
    "commandId": "info",
    "parameters": [
      {
        "name": "term",
        "value": "sadfasdf"
      }
    ],
    "queryOptions": {
      "count": 25,
      "skip": 0
    }
  },
  "imdisplayname": redacted,
  "conversation": {
    "id": "19:2402b3bf-99b7-4979-9970-6ad9528a3ba7_2cf61cbd-a711-4f9f-95b4-92a7b20cb017@unq.gbl.spaces"
  }
}

This is what my bot received:

{
  "name": "composeExtension/query",
  "type": "invoke",
  "timestamp": "2023-03-31T03:49:00.907Z",
  "localTimestamp": "2023-03-30T21:49:00.907-06:00",
  "id": "f:1a1a8681-8e28-32df-3441-88a71477e5c1",
  "channelId": "msteams",
  "serviceUrl": "https://smba.trafficmanager.net/amer/",
  "from": {
    "id": "29:1kCq75A-g8wVc36XZqhI504r073ByA0Uk0KMcIAIWMvrm_2iivPfbNZ5mDObiz_gFfmkcf2hioAZO5NfG_mfiRw",
    "name": redacted,
    "aadObjectId": "2402b3bf-99b7-4979-9970-6ad9528a3ba7"
  },
  "conversation": {
    "conversationType": "personal",
    "tenantId": redacted,
    "id": "a:1HlPo9qAhR5bbfnkumzXUvpkO2yQ4z1lt89QIby3dqHrGLvfRHwnkoPmTOGjNqSGYTDzySM9jJbil18BJ7TOh27eedpe7_rpaHjjKBi62f3v4KaXZShqFtUetdPz2TZ7w"
  },
  "recipient": {
    "id": "28:2cf61cbd-a711-4f9f-95b4-92a7b20cb017",
    "name": "CometDev"
  },
  "entities": [
    {
      "locale": "en-US",
      "country": "US",
      "platform": "Web",
      "timezone": "America/Denver",
      "type": "clientInfo"
    }
  ],
  "channelData": {
    "tenant": {
      "id": redacted
    },
    "source": {
      "name": "compose"
    }
  },
  "value": {
    "commandId": "info",
    "parameters": [
      {
        "name": "term",
        "value": "sadfasdf"
      }
    ],
    "queryOptions": {
      "count": 25,
      "skip": 0
    }
  },
  "locale": "en-US",
  "localTimezone": "America/Denver"
}

Notice the conversation IDs are very different. Why is the bot receiving a different (probably wrong) conversation ID?

We checked at our end, and we are getting below response which bot receives and compared that this is the correct conversation id

{
    "name": "composeExtension/query",
    "type": "invoke",
    "timestamp": "2023-04-03T09:27:26.543Z",
    "localTimestamp": "2023-04-03T14:57:26.543+05:30",
    "id": "f:c38f0ca0-6dfa-f625-40fe-9140a9cd780e",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
        "id": "29:1GdHzmtVE_hN2wPrVQSb0fdMuI-HG8_kDOUXSNcf1pCKVfQQNnDqsRBZ6kGaAVUlNYy7BzXbQc1dg38oMTNnKOg",
        "name": "MOD Administrator",
        "aadObjectId": "4ebcc4d0-291b-4154-a85f-a89cd77aefa8"
    },
    "conversation": {
        "isGroup": true,
        "conversationType": "groupChat",
        "tenantId": "36a708ef-700d-4d60-9de0-0a5f7b7693df",
        "id": "19:ed13a8deaace437c814032df49c8be90@thread.v2"
    },
    "recipient": {
        "id": "28:448ec85c-4395-4f80-b5a1-cd3bdefd1f5b",
        "name": "AzBotPSD"
    },
    "entities": [
        {
            "locale": "en-US",
            "country": "US",
            "platform": "Web",
            "timezone": "Asia/Calcutta",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "36a708ef-700d-4d60-9de0-0a5f7b7693df"
        },
        "source": {
            "name": "compose"
        }
    },
    "value": {
        "commandId": "searchQuery",
        "parameters": [
            {
                "name": "initialRun",
                "value": "true"
            }
        ],
        "queryOptions": {
            "count": 25,
            "skip": 0
        }
    },
    "locale": "en-US",
    "localTimezone": "Asia/Calcutta"
}

Could you please let us know how you are getting the response in console with incorrect conversation id?

bandtank commented 1 year ago

I don't know if the conversation ID is a problem yet because I can't get the endpoint to respond in the proper way. The first thing I need to know is:

Prasad-MSFT commented 1 year ago

@bandtank - Please check if you are looking for endpoint as mentioned below: https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-send-and-receive-messages?view=azure-bot-service-4.0#send-the-reply

bandtank commented 1 year ago

@Prasad-MSFT I wrote that documentation in a github issue, which was later added to the linked page. It does not apply to this situation. If the endpoint is the same, the instructions for a messaging extension are not explained because there is no activity ID in several contexts when a composeExtension query is sent. The response structure is also not what is shown at that link. The type is wrong, parameters are missing, etc.

Prasad-MSFT commented 1 year ago

Okay, we will check this with engineering team and will update accordingly. Thanks!

bandtank commented 1 year ago

Has there been an update?

Prasad-MSFT commented 1 year ago

Apologies. Currently there is no update from engineering team. We are following up with them. We will inform you once we get any update. Thanks!

bandtank commented 1 year ago

Any updates? I have the extension in Teams and it has the desired tabs:

image

image

Nothing I send in response to this message works:

[
  {
    "name": "composeExtension/query",
    "type": "invoke",
    "timestamp": "2023-05-12T20:44:55.541Z",
    "localTimestamp": "2023-05-12T14:44:55.541-06:00",
    "id": "f:746cc5ab-959c-b7c6-2504-00c76cd83307",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
      "id": "29:1kCq75A-g8wVc36XZqhI504r073ByA0Uk0KMcIAIWMvrm_2iivPfbNZ5mDObiz_gFfmkcf2hioAZO5NfG_mfiRw",
      "name": "Anthony Andriano",
      "aadObjectId": "2402b3bf-99b7-4979-9970-6ad9528a3ba7"
    },
    "conversation": {
      "conversationType": "personal",
      "tenantId": "bcd4c429-1111-1111-1111-111111111111",
      "id": "a:1EhVX34pEmKNtjGyIVdtjAJiH6UgENmFZaHECCBGLe0bpNFOytjc3VHDfRTbknG8pDliFTZfwXP4IXyCM8tftZvvVgZ_OBdXuJj5nSd6i22c_C7s8qm3uOYqxVN4GEpQB"
    },
    "recipient": {
      "id": "28:2cf61cbd-a711-4f9f-95b4-92a7b20cb017",
      "name": "CometDev"
    },
    "entities": [
      {
        "locale": "en-US",
        "country": "US",
        "platform": "Web",
        "timezone": "America/Denver",
        "type": "clientInfo"
      }
    ],
    "channelData": {
      "tenant": {
        "id": "bcd4c429-1111-1111-1111-111111111111"
      },
      "source": {
        "name": "compose"
      }
    },
    "value": {
      "commandId": "info",
      "parameters": [
        {
          "name": "initialRun",
          "value": "true"
        }
      ],
      "queryOptions": {
        "count": 25,
        "skip": 0
      }
    },
    "locale": "en-US",
    "localTimezone": "America/Denver",
    "receivedAt": "2023-05-12 20:44:55",
    "parent": {
      "id": "60e77309b0a75b5b2",
      "type": "User"
    }
  }
]

I still need to know which endpoint to send the response to as well as how the JSON should be structured.

Prasad-MSFT commented 1 year ago

@bandtank - Apologies. Currently there is no update to share. However, we are constantly following up with engineering team on this. We will inform you once we get any update. Thanks!