OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
426 stars 193 forks source link

Channel moderation settings are evaluated incorrectly when posting as a bot. #2323

Open LeonYasoon opened 3 months ago

LeonYasoon commented 3 months ago

The channel moderation settings allow users in the Teams UI to disallow bots from posting into the channel:

Screenshot 2024-05-13 at 13 53 46

When unticking that box and the turning the whole channel moderation feature off

Screenshot 2024-05-13 at 13 53 54

bots still cannot post into that channel. The error message thrown by the botbuilder framework is "User blocked conversation with the bot."

Turning the moderation back on, ticking the box, then turning it off makes it work again.

-> It seems like the "Allow bots to post into this channel" box is evaluated regardless of the channel moderation feature being on or off for that channel.

Steps to reproduce the behavior:

  1. Go to Teams -> Channel settings -> Turn on channel moderation
  2. Make sure the "Allow bots to post into this channel" box is NOT checked.
  3. Turn off channel moderation
  4. Try to post into that channel with the botbuilder sdk client.conversations.sendToConversation()
  5. Receive the "User blocked conversation with the bot." error.
  6. Turn on channel moderation and tick that box, turn channel moderation back off
  7. Post again -> no error.

Expected behavior The expected behaviour would be that channel moderation settings are only evaluated when channel moderation is on.

ChetanSharma-msft commented 3 months ago

Hello @LeonYasoon - Thanks for raising your query. Could you please share the complete code if possible so that we can quickly investigate your issue?

LeonYasoon commented 3 months ago

Hi @ChetanSharma-msft The necessary code to reproduce is related to the botbuilder SDK:

botClient.conversations.sendToConversation(channelId, activity)

Run this command in these scenarios:

  1. Before turning channel moderation on -> it works (expected)
  2. Turn channel moderation on and untick the "Allow bot posts" checkbox -> doesn't work (expected)
  3. Turn off channel moderation -> doesnt work (not expected)
Vikram-MSFT commented 3 months ago

Hi @LeonYasoon - We are bit confused here. Let us know if our understanding correct or not 1.First your channel moderation is off, and bot was able to post messages in channel. (Expected)

2.Then you turned on channel moderation and "Allow bots to post into this channel" box is NOT checked => Bot not able to post expected)

3.Then again you turned off channel moderation and bot is able to post messages in channel. (Here you want to know if it expected behaviour or not)

tobiasviehweger commented 3 months ago

Hi @Vikram-MSFT - @LeonYasoon is currently oof, but let me explain. 1 & 2 are correct, but what we are seeing is 3: once you turn off channel moderation (and the bot checkbox is still unchecked) - it will still be blocked! Even though moderation is turned off.

See my video with details:

  1. I post with moderation off (never turned on for this channel, bot can post correctly)
  2. I post with moderation on (but "Allow bots to submit channel messages" = off) => {"code":"ConversationBlockedByUser","message":"User blocked the conversation with the bot."}}'.” (correct)
  3. I post with moderation turned off again (leaving "Allow bots to submit channel messages" = off) => still {"code":"ConversationBlockedByUser","message":"User blocked the conversation with the bot."}}'.” (incorrect behavior)
  4. Only when you check the "Allow bots to submit channel messages" before turning moderation off, it will work

So it seems the backend only evaluates the "Allow bots to submit channel messages" checkbox, but not the "moderation" = off, which seems wrong.

Video: https://yasoon-my.sharepoint.com/:v:/p/tobias_viehweger/EaDaZI8Z_6tOj-0UL1xKEVMBLW17bzZ9gfXgm9emUz9Arg?nav=eyJyZWZlcnJhbEluZm8iOnsicmVmZXJyYWxBcHAiOiJTdHJlYW1XZWJBcHAiLCJyZWZlcnJhbFZpZXciOiJTaGFyZURpYWxvZy1MaW5rIiwicmVmZXJyYWxBcHBQbGF0Zm9ybSI6IldlYiIsInJlZmVycmFsTW9kZSI6InZpZXcifX0%3D&e=qiQIuC

Vikram-MSFT commented 3 months ago

Hello @LeonYasoon We are also able to repro this issue, we will check internally and get back to you. Update : We raised a bug for this issue, we will keep you posted on the updates. Thank you