Forum Discussion

jasonburek's avatar
jasonburek
Copper Contributor
Apr 10, 2023

Channel context from command box

I've been exploring using the command box as an entry point to my application. After the user is done, I'd like to post a card to a channel. The problem I'm running into is that I can't figure out how to get the current channel context from within the command box.

 

I can see that the Praise app does exactly the type of thing that I'm trying to do. If you type @Priase in the command box the app opens a task module for you to build your card. When you click "Send" it posts the card to the currently open channel.

 

I tried looking at the data that I get from the invoke and there doesn't appear to be anything related to the channel in there. I also tried to use the botMessagePreview response. When I did, the send button was disabled and there was an error message that said that you could only send the card in the context of a channel.

 

How do you get the channel context when invoked from the command box? Praise clearly has a way of doing it so it must be possible but I can't seem to figure out how.

  • jasonburek's avatar
    jasonburek
    Copper Contributor
    I think I at least partially figured this out. I haven't figured out how to get the channel context from within the messaging extension itself but it looks like the javascript context does contain that information so I can use it from there.
    • Prasad_Das-MSFT's avatar
      Prasad_Das-MSFT
      Icon for Microsoft rankMicrosoft

      jasonburek - When we tried to invoke messaging extension from command box in channel scope,
      we are getting context as below: 

      {
          "name": "composeExtension/query",
          "type": "invoke",
          "timestamp": "2023-04-11T06:37:01.408Z",
          "localTimestamp": "2023-04-11T12:07:01.408+05:30",
          "id": "f:66e020e0-e1a2-ef8e-41fe-e53714d96ce8",
          "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": {
              "tenantId": "36a708ef-700d-4d60-9de0-0a5f7b7693df",
              "id": "29:1GdHzmtVE_hN2wPrVQSb0fdMuI-HG8_kDOUXSNcf1pCKVfQQNnDqsRBZ6kGaAVUlNYy7BzXbQc1dg38oMTNnKOg"
          },
          "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": "powerbar"
              }
          },
          "value": {
              "commandId": "searchQuery",
              "parameters": [
                  {
                      "name": "initialRun",
                      "value": "true"
                  }
              ],
              "queryOptions": {
                  "skip": 0,
                  "count": 25
              }
          },
          "locale": "en-US",
          "localTimezone": "Asia/Calcutta"
      }

       

      • jasonburek's avatar
        jasonburek
        Copper Contributor
        That looks similar to what I'm seeing. There is a section for "conversation" but that ID matches the From ID so it appears to be a reference to the 1:1 conversation with the user. I'm not seeing anything in there that would lead me back to the Team/Channel that's currently open.

Resources