botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Can someone point me to some code inplementing list view for fb?

Open ishandutta2007 opened this issue 9 years ago • 5 comments

I am having trouble to get exact look and feel like this, https://developers.facebook.com/docs/messenger-platform/send-api-reference/list-template

ishandutta2007 avatar Jan 03 '17 17:01 ishandutta2007

You'll need to send a raw FB message via ChannelData/SourceEvent to display a List Template.

craigjensen avatar Jan 04 '17 23:01 craigjensen

@craigjensen: I have attempted to use the sourceEvent workaround but with no avail.

Every time I try to send this, I get a log out of the following: Error: Request to 'https://facebook.botframework.com/v3/conversations/1314733455250332-1257481210956934/activities/mid.1484799216105%3Acfddfe3b84' failed: [400] Bad Request

This is my code for trying to do so:

var card = {
    facebook: {
        attachment: {
            type: "template",
            payload: {
                template_type: "list",
                elements: [
                    {
                        title: 'title',
                        image_url: null,
                        subtitle: 'subtitle subtitle subtitle',
                        buttons: [
                        	{
                        		title: 'title',
                        		type: 'web_url',
                            	url: 'http://www.google.com.au',
                            	messenger_extensions: false,
                            	webview_height_ratio: 'compact',
                            	fallback_url: 'http://google.com.au'
                        	}
                        ]
                    },
                    {
                        title: 'title',
                        image_url: null,
                        subtitle: 'subtitle subtitle subtitle',
                        buttons: [
                        	{
                        		title: 'title',
                        		type: 'web_url',
                            	url: 'http://www.google.com.au',
                            	messenger_extensions: false,
                            	webview_height_ratio: 'compact',
                            	fallback_url: 'http://google.com.au'
                        	}
                        ]
                    }
                ]
            }
        }
    }
}

var msg = new builder.Message(session).sourceEvent(card);

session.send(msg);

Any help would be highly appreciated.

Thanks, Scott

scottmcconnell avatar Jan 19 '17 04:01 scottmcconnell

Try this:

var card =  {
  facebook: {
    attachment: {
      type: "template",
      payload: {
        template_type: "list",
        top_element_style: "compact",
        elements: [
          {
            title: 'title',
            image_url: null,
            subtitle: 'subtitle subtitle subtitle',
            buttons: [
              {
                title: 'title',
                type: 'web_url',
                url: 'http://www.google.com.au',
                webview_height_ratio: 'compact'
              }
            ]
          },
          {
            title: 'title',
            image_url: null,
            subtitle: 'subtitle subtitle subtitle',
            buttons: [
              {
                title: 'title',
                type: 'web_url',
                url: 'http://www.google.com.au',
                webview_height_ratio: 'compact'
              }
            ]
          }
        ]
      }
    }
  }
}

craigjensen avatar Jan 19 '17 16:01 craigjensen

@craigjensen; Wow. I don't know how I could have missed that. I was using the example on the FB dev page - I guess that's out of date.

Thanks a ton for that.

scottmcconnell avatar Jan 20 '17 01:01 scottmcconnell

Glad to hear its working now. I'll go ahead and close this issue. Feel free to reopen if needed

craigjensen avatar Jan 20 '17 01:01 craigjensen