How config bot for availably for only channel

76 views Asked by At

I would like the application, when called via the chat bar

enter image description here enter image description here

to first check whether the user is in "groupChat" or in "channel". If in "groupChat", it should display a card with the information "Channel Only". If in "channel", it should show the other options available, i.e. a search query and the possibility to create a card.... how to do this?

I've tried config manifest.json in appPackage:

...more code
"bots": [
            {
            "botId": "${{BOT_ID}}",
        "scopes": ["team"],
        "supportsFiles": false,
        "isNotificationOnly": false,
        "commandLists": [
            {
                "scopes": ["team"],
                "commands": [
                    {
                            "title": "welcome",
                        "description": "Resend welcome card of this Bot"
                    },
                    {
                        "title": "learn",
                        "description": "Learn about Adaptive Card and Bot Command"
                    }
                ]
            }
        ]
    }
],
.... more code

and too add code in index.js:


server.post('/api/messages', async (req, res) => {
    await adapter.process(req, res, async context => {
        const conversationType = context.activity.conversation.conversationType

        if (conversationType === 'groupChat') {
            const card = cardTools.AdaptiveCards.declareWithoutData(rawOnlyChannel).render()
            await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] })
        } else if (conversationType === 'channel') {
            await bot.run(context)
        } else {
            await context.sendActivity('Unknown type of conversation')
        }
    })
})

and I create new card in folder adaptiveCards:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4",
    "body": [
        {
            "type": "TextBlock",
            "text": "No authority",
            "wrap": true,
            "horizontalAlignment": "Center",
            "size": "Large",
            "weight": "Bolder",
            "color": "Attention"
        },
        {
            "type": "TextBlock",
            "text": "Operation only available on channels",
            "wrap": true,
            "fontType": "Default",
            "horizontalAlignment": "Center",
            "color": "Warning"
        }
    ],
    "verticalContentAlignment": "Center"
}

but not only do I get such errors in the console:

[onTurnError] unhandled error: Error: The bot is not part of the conversation roster.
RestError: The bot is not part of the conversation roster.
    at new RestError (D:\...\node_modules\@azure\ms-rest-js\dist\msRest.node.js:2479:28)
    at D:\...\bot\node_modules\@azure\ms-rest-js\dist\msRest.node.js:3644:37
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'BotNotInConversationRoster',
  statusCode: 403,
  request: WebResource {
    streamResponseBody: false,
    url: 'https://smba.trafficmanager.net/emea/v3/conversations/19%3A7990a50d-8507-4843-967c-c85c7bbbada2_8d058514-b4c4-415b-bf87-346bfcbaf116%40unq.gbl.spaces/activities/f%3A0711bd76-0c16-608b-ab24-b788a8fd0a31',
    method: 'POST',
    headers: HttpHeaders { _headersMap: [Object] },
    body: '{"type":"message","serviceUrl":"https://smba.trafficmanager.net/emea/","channelId":"msteams","from":{"id":"28:2a7dc32d-240a-4a73-bfe3-01bb14a08089","name":"..."},"conversation":{"isGroup":true,"conversationType":"groupChat","id":"...","tenantId":"..."},"recipient":{"id":"...","name":"...","aadObjectId":"..."},"locale":"...","text":"The bot encountered an unhandled error:\\n The bot is not part of the conversation roster.","inputHint":"acceptingInput","replyToId":"f:0711bd76-0c16-608b-ab24-b788a8fd0a31"}',
    query: undefined,
    formData: undefined,
    withCredentials: false,
    abortSignal: undefined,
    timeout: 0,
    onUploadProgress: undefined,
    onDownloadProgress: undefined,
    proxySettings: undefined,
    keepAlive: undefined,
    agentSettings: undefined,
    redirectLimit: undefined,
    operationSpec: {
      httpMethod: 'POST',
      path: 'v3/conversations/{conversationId}/activities/{activityId}',
      urlParameters: [Array],
      headerParameters: [Array],
      requestBody: [Object],
      responses: [Object],
      serializer: [Serializer]
    }
  },
  response: {
    body: '{"error":{"code":"BotNotInConversationRoster","message":"The bot is not part of the conversation roster."}}',
    headers: HttpHeaders { _headersMap: [Object] },
    status: 403
  },
  body: {
    error: {
      code: 'BotNotInConversationRoster',
      message: 'The bot is not part of the conversation roster.'
    }
  }
}

this additionally does not run as I intended, the bot only checks after the user action of selecting a tab or searching.

I create app by using toolit teams in vs code. I'm using: Bot, Personal App and Messaging extension

I've been struggling with this for a couple of days now and can't come to a solution, so I'm asking for some guidance on what I'm doing wrong and how I can configure the app correctly so that before running the commandId check it first checks before the user interaction to see if they are in the channel....

0

There are 0 answers