I'm trying to implement a bot to send proactive messages. I made a proof of concept in NodeJS that works:
const { BotFrameworkAdapter } = require('botbuilder');
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
adapter.onTurnError = async (error) => {
console.error(error);
};
const cr = require('./test_cr.json');
adapter.continueConversation(cr, async (turnContext) => {
await turnContext.sendActivity('Node SDK proactive message')
});
Yet when I try to recreate this example using the Java SDK, I get com.microsoft.bot.connector.rest.ErrorResponseException: Status code 401, {"message":"Authorization has been denied for this request."}
.
String appId = System.getenv("MicrosoftAppId");
String appPassword = System.getenv("MicrosoftAppPassword");
BotFrameworkAdapter bot = new BotFrameworkAdapter(new SimpleCredentialProvider(appId, appPassword));
ConversationReference cr = mapper.readValue(new File("test_cr.json"), ConversationReference.class);
CompletableFuture<Void> cf = bot.continueConversation(appId, cr, turnContext -> turnContext.sendActivity("Java SDK proactive message").thenApply(resourceResponse -> null));
cf.get();
The conversation reference and app credentials should be the same for both examples. Am I not setting up the Java bot correctly? For reference, I'm using a pretty barebones conversation reference:
{
"channelId":"msteams",
"serviceUrl":"https://smba.trafficmanager.net/amer/",
"conversation":{
"isGroup":true,
"conversationType":"channel",
"tenantId":"xxxxxx",
"id":"xxxxxx"
}
}
question from:
https://stackoverflow.com/questions/66055871/java-bot-sdk-throws-401-error-for-proactive-message 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…