Forum Discussion
themashcodee
Jun 19, 2023Copper Contributor
RestError: Authorization has been denied for this request
I am trying to create(createConversationAsync) a conversation (dm) in microsoft teams bot framework, but I am getting this error err: RestError: Authorization has been denied for this request
I have created the bot with vscode's extension teams toolkit and I am trying to send a dm to the user when submits a task module, below is the code I am using
import { MessageFactory, TeamsInfo, TurnContext } from "botbuilder"
const BOT_APP_ID = process.env["BOT_ID"]
export async function send_dm(context: TurnContext) {
const user = await TeamsInfo.getMember(context, context.activity.from.id)
const tenantId = context.activity.conversation.tenantId
const channelId = context.activity.channelId
const serviceUrl = context.activity.serviceUrl
const message = MessageFactory.text(`Hello I'm a Teams conversation bot.`)
await context.adapter.createConversationAsync(
BOT_APP_ID,
channelId,
serviceUrl,
BOT_APP_ID,
{
members: [user],
bot: context.activity.recipient,
isGroup: false,
tenantId,
activity: context.activity,
channelData: undefined,
},
async (newContext) => {
await newContext.sendActivity(message)
}
)
}
I have created a test tenant with developer program and I am running my bot in the local with the help of team toolkit vscode extension.
I am attaching my package.json, manifest.json for reference let me know if you need something else
thanks in advance.
8 Replies
Sort By
- mrpsycoxCopper ContributorHi everyone,
I'm trying to develop an echo-bot provided from you (https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/02.echo-bot) and I keep receiveing the same generic error "Error: Authorization has been denied for this request.". What do I need to do? Also, I've created a Azure Support Request (N° 2306210050004437) and I didn't receive any response.- Sayali-MSFT
Microsoft
mrpsycox -Could you please directly add App Id(Instead of
process.env.MicrosoftAppId) and Password value in index.JS file like below and check it once.- Sayali-MSFT
Microsoft
mrpsycox -Did you get chance to check?
- Sayali-MSFT
Microsoft
mrpsycox -Thanks for sharing the sample, we will test this from our end and let you know the update.
- Sayali-MSFT
Microsoft
themashcodee- Thanks for reporting your issue.
We will check this at our end and will get back to you.- ketanchawda
Microsoft
Sayali-MSFT also getting the similar error.
- Sayali-MSFT
Microsoft
themashcodee- We have tried the above scenario with the below sample to repro the issue, but it working fine from our end.
Microsoft Teams Version 1.6.00.16971 (64-bit)
Sample Link- Microsoft-Teams-Samples/samples/bot-conversation/nodejs/bots/teamsConversationBot.js at 5e74a4af173963edb1ef93481537238479d45b0d · OfficeDev/Microsoft-Teams-Samples (github.com)