Reputation: 101
I started learning the Microsoft Bot Framework, but when I am trying to use a Connector it always returns:
"message": "An error has occurred.",
"exceptionMessage": "Unable to deserialize the response.",
"exceptionType": "Microsoft.Rest.RestException",
Here is the code
public async Task<Message> Post([FromBody]Message message)
{
try
{
if (message.Type == "Message")
{
// calculate something for us to return
//int length = (message.Text ?? string.Empty).Length;
// return our reply to the user
// return message.CreateReplyMessage($"You sent {length} characters");
//var counter = message.GetBotPerUserInConversationData<int>("counter");
//// create a reply message
//Message replyMessage = message.CreateReplyMessage($"{++counter} You said:{message.Text}");
//// save our new counter by adding it to the outgoing message
//replyMessage.SetBotPerUserInConversationData("counter", counter);
//// return our reply to the user
////return replyMessage;
// return message.CreateReplyMessage("Yo, I got it.", "en");
// var replyMessage = message.CreateReplyMessage("Yo, I heard you.", "en");
// var connectorr = new ConnectorClient();
// connectorr.BaseUri = new Uri("http://localhost:3978/");
//return await connectorr.Messages.SendMessageAsync(replyMessage);
var connector = new ConnectorClient();
connector.BaseUri = new Uri("http://localhost:3978/api/messages");
await connector.Messages.SendMessageAsync(message.CreateReplyMessage($"You said:{message.Text}"));
await connector.Messages.SendMessageAsync(message.CreateReplyMessage("Yo 2.", "en"));
await connector.Messages.SendMessageAsync(message.CreateReplyMessage("Yo 3.", "en"));
return null;
}
else
{
return HandleSystemMessage(message);
}
}
catch (Exception ex)
{
throw;
}
}
Upvotes: 4
Views: 2357
Reputation: 2590
You should upgrade it to latest version which is 3.8.0. Have a look at: https://learn.microsoft.com/en-us/bot-framework/resources-upgrade-to-v3
Upvotes: 1
Reputation: 4441
Instead of await connector.Messages.SendMessageAsync(message.CreateReplyMessage($"You said:{message.Text}"));
use await context.PostAsync($"You said: {activity.Text}");
and see if that works.
Upvotes: 0
Reputation: 1583
Try to migrate according to V3.0 specification and see if it works now. I faced some similar issues when code was targeting v1.0 and bot was registered to v3.0.
Upvotes: 0
Reputation: 652
It seems that you create a connector inside the bot itset. I am not sure why you want to do that as this seems to create a circular solution. You can use the ConnectorCLient to create your own messageclient that connects to your bot. Is this what you want to achieve?
If you just want to reply a message based on the message you need to use:
return message.CreateReplyMessage("Yo, I got it.", "en");
You can connect to you bot by using the emulator or connect it to Skype, FB messanger to get it going.
Upvotes: 0