I use spring boot and botbuilder-java library to create a bot on microsoft teams. I registre my bot on bot framework. I use ngrok to make a proxy so that the bot frame can access to my local port. Then when i send a request and then response. I got com.microsoft.bot.connector.models.ErrorResponseException: Status code 401,
this is link which i follow to do. https://medium.com/@oleksiydzhus/how-to-build-a-bot-with-microsoft-bot-framework-and-spring-boot-558fb32b7d3c
i already have the appId and appPassword, but when i send the response, the currentToken is null. I guess maybe this is the problem. but i don't know how to config it out.
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class BotConfig {
@Autowired
private Environment environment;
@Bean(name = "credentials")
public MicrosoftAppCredentials getCredentials() {
return new MicrosoftAppCredentials("6b157339-e091-4c33-b9e3-7e7e035d006e", "<password>");
}
@Bean
public List<ResourceResponse> getResponses(){
return new ArrayList<>();
}
}
this is my handler
@RestController
@RequestMapping(path = "/api/messages")
public class BotMessagesHandler {
@Autowired
private MicrosoftAppCredentials credentials;
@Autowired
private List<ResourceResponse> responses;
@PostMapping(path = "")
public List<ResourceResponse> create(@RequestBody @Valid
@JsonDeserialize(using = DateTimeDeserializer.class) Activity activity) {
ConnectorClient connector =
new ConnectorClientImpl(activity.serviceUrl(), credentials);
Activity echoActivity = ActivityCreator.createEchoActivity(activity);
Activity checkedActivity = ActivityCreator.createSpellCheckedActivity(activity);
Conversations conversation = ConversationCreator.createResponseConversation(connector);
ResourceResponse echoResponse =
ResourceResponseSender.send(conversation, activity, echoActivity);
responses.add(echoResponse);
ResourceResponse spellCheckedResponse =
ResourceResponseSender.send(conversation, activity, checkedActivity);
responses.add(spellCheckedResponse);
return responses;
}
}
com.microsoft.bot.connector.models.ErrorResponseException: Status code 401,
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_211]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_211]
at com.microsoft.rest.ServiceResponseBuilder.build(ServiceResponseBuilder.java:122) ~[client-runtime-1.2.1.jar:na]
at com.microsoft.azure.AzureResponseBuilder.build(AzureResponseBuilder.java:56) ~[azure-client-runtime-1.2.1.jar:na]
at com.microsoft.bot.connector.implementation.ConversationsImpl.sendToConversationDelegate(ConversationsImpl.java:510) ~[bot-connector-4.0.0-a1.jar:na]
at com.microsoft.bot.connector.implementation.ConversationsImpl.access$200(ConversationsImpl.java:48) ~[bot-connector-4.0.0-a1.jar:na]
at com.microsoft.bot.connector.implementation.ConversationsImpl$12.call(ConversationsImpl.java:495) ~[bot-connector-4.0.0-a1.jar:na]
at com.microsoft.bot.connector.implementation.ConversationsImpl$12.call(ConversationsImpl.java:491) ~[bot-connector-4.0.0-a1.jar:na]