Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

node.js - Error while sending proactive message to MS Teams

Hi I am trying to send proactive message to MS Teams. I already know the conversationId and serviceUrl which I got from onTeamMembersAddedEvent. When I call /api/notify from browser, I am getting an error, and message is not sent.

Here is the handler on index.js:

const adapter = new BotFrameworkAdapter({
    appId: process.env.BotId,
    appPassword: process.env.BotPassword
});

server.get('/api/notify', (req, res) => {
    let conversationId = "29:1OdRHJr7..."; //90 character value
    let serviceUrl = 'https://smba.trafficmanager.net/amer/';

    let conversationReference = {
        conversation: { id: conversationId },
        serviceUrl: serviceUrl
    }

    adapter.continueConversation(conversationReference, async turnContext => {

        MicrosoftAppCredentials.trustServiceUrl(serviceUrl);

        await turnContext.sendActivity('Proactively saying **Hello**');
    });

    res.end();
});

And I am getting following error:

[onTurnError] unhandled error: Error: Authorization has been denied for this request.
(node:62313) UnhandledPromiseRejectionWarning: Error: Authorization has been denied for this request.
    at new RestError (/Users/paudelb/Workspace/msteams/Reminder3/node_modules/@azure/ms-rest-js/dist/msRest.node.js:1397:28)
    at /Users/paudelb/Workspace/msteams/Reminder3/node_modules/@azure/ms-rest-js/dist/msRest.node.js:1849:37
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:62313) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:62313) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
question from:https://stackoverflow.com/questions/66056129/error-while-sending-proactive-message-to-ms-teams

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It sounds like something's wrong with your app id and/or app password not getting loaded properly. The only other reason I've seen for an authorization error is if the user has uninstalled the app - not sure if that's applicable to you. You'd usually get a 401:Forbidden in this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...