Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't send image and quick replies #4

Open
stefanmm opened this issue Mar 6, 2017 · 3 comments
Open

Can't send image and quick replies #4

stefanmm opened this issue Mar 6, 2017 · 3 comments

Comments

@stefanmm
Copy link

stefanmm commented Mar 6, 2017

Hi,

I tried to send image and quick replies in one message (or in two in row) but it's not possible. I have working code but for native Facebook messenger bot code, not for framework:

message: {
            attachment: {
                type: "image",
                payload: {
                    url: "ULR_OF_IMAGE"
                }
            },
            quick_replies: [{
                    content_type: "text",
                    title: "Scroll down",
                    payload: "scroll_down_payload"
                },
                {
                    content_type: "text",
                    title: "Scroll up",
                    payload: "YOUR_DEFINED_PAYLOAD_FOR_NEXT_IMAGE"
                },
                {
                    content_type: "text",
                    title: "Scroll top",
                    payload: "YOUR_DEFINED_PAYLOAD_FOR_NEXT_IMAGE"
                }
            ]
        }
@ghost
Copy link

ghost commented Mar 7, 2017

Hi Stefan,

this is not possible. If you want to send a image first and them quick replies do so :

function cb(){
 bot.sendQuickReplies(userId, message, replies)
}
bot.sendImageMessage(userId, imageUrl, null, cb)

cheers,

Franzus

@stefanmm
Copy link
Author

stefanmm commented Mar 7, 2017

Thanks. I found other solution, but I changed fb-bot-framework/index.js file:

FBBotFramework.prototype.sendImageMessage = function (recipient, imageUrl, replies, notificationType, cb) {
    var messageData = {
        attachment: {
            type: "image",
            payload: {url: imageUrl}
        },
            quick_replies: replies
    };

    this.send(recipient, messageData, notificationType, cb);
};

So, in my file:

function sendUrlMessage(userId, siteUrl, topOffset) {
var imageUrl = "IMG_URL";
	
	var replies = [
        {
            "content_type": "text",
            "title": "title1",
            "payload": "payload1"
        },
        {
            "content_type": "text",
            "title": "title2",
            "payload": "payload2"
        }
    ];
	bot.sendImageMessage(userId, imageUrl, replies);
}

@henryckh
Copy link
Contributor

henryckh commented Nov 28, 2017

You can achieve this by using send() API,
with the call like this

var messageData = {
    quick_replies: [
        {
            "content_type": "text",
            "title": "Good",
            "payload": "thumbs_up"
        },
        {
            "content_type": "text",
            "title": "Bad",
            "payload": "thumbs_down"
        }],
    attachment: {
        type: "image",
        payload: {
            url: "http://placehold.it/240x240&text=helloworld"
        }
    }
};
bot.send(recipient, messageData, FBBotFramework.NOTIFICATION_TYPE.REGULAR, function (err, result) {
    if(err) {
     // handle error
    }
    // response
});

I would suggest a new generic handling of sendMessage with custom payload to the framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants