Message dublicate in Facebook messenger
I have built the bot, connected it to Skype and Facebook Messenger. The bot works great for Skype. I have the issue : bot responds twice in Messenger when sends an attachment. Ultimately the user gets two identical attachments(images in my case) at the same time: example
Here is the code responsible for sending an attachment:
var message = await argument;
Attachment attachment = new Attachment()
{
ContentUrl = "http://newevolutiondesigns.com/images/freebies/cat-wallpaper-2.jpg",
ContentType = "image/png"
}
message.Attachments.Add(attachment);
await context.PostAsync(message);
context.Wait(MessageReceivedAsync);
When I remove an attachment from code and send just a text, the bot works correctly and responds by one message in Messenger. Again, the code above (with sending an attachments) works for skype.
So, now everything works, because I changed my code a little bit:
var reply = context.MakeMessage();
reply.Attachments = new List<Attachment>();
Attachment attachment = new Attachment()
{
ContentUrl = url,
ContentType = "image"
};
reply.Attachments.Add(attachment);
await context.PostAsync(reply);
Instead of creating one attachment I created a list of attachments which holds one attachment. But I still can't understand why my previous code didn't work for Messenger
Your previous code wasn't working properly because you weren't creating the reply message correctly; call to: context.MakeMessage(). Your first code snippet is trying to add the attachment to the incoming message and send the modified incoming message back to the user and the second snippet generates the empty reply message and populate it with the expected attachment.
Ok, it's clear for me, thank you!