Forum Discussion

themashcodee's avatar
themashcodee
Copper Contributor
Jun 19, 2023

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

Resources