1

I am writing a facebook bot using MS Bot Framework. I am able to send text replies successfully, but I can't seem to send a picture.

Microsoft has the following example here - http://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html

replyMessage.Attachments.Add(new Attachment()
{
    ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
    ContentType = "image/png",
    Name = "Bender_Rodriguez.png"      
});

That code doesn't work for me - it throws this error:

Object reference not set to an instance of an object.

Bot_Application1.MessagesController.d__0.MoveNext()
in C:\Users------\Dropbox\code\Bot Application1\Bot
Application1\Controllers\MessagesController.cs:line 92

Line 92 is where I call the .Attachments.Add() method.

I've tried to modify the code to make sure it has no null properties inside, so I added non-null Content and ThumbnailUrl, but this also doesn't work (with or without these two parameters). It's exactly the same error as above when calling the Add() method.

Activity reply3 = activity.CreateReply("blah");

Attachment pic = new Attachment();
pic.ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png";
pic.ContentType = "image/png";
pic.Name = "Bender_Rodriguez.png";
pic.Content = "Test";
pic.ThumbnailUrl = pic.ContentUrl;

reply3.Attachments.Add(pic);

await connector.Conversations.ReplyToActivityAsync(reply3);

What am I doing wrong?

1
  • 1
    replyMessage is null or Attachments?? Commented Jul 12, 2016 at 8:53

1 Answer 1

2

Turns out you need to add a line that was not mentioned in the documentation:

                reply3.Attachments = new List<Attachment>();

After initializing the Attachments it works fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.