claudiajs / claudia-bot-builder

Create chat bots for Facebook Messenger, Slack, Amazon Alexa, Skype, Telegram, Viber, Line, GroupMe, Kik and Twilio and deploy to AWS Lambda in minutes
https://claudiajs.com/claudia-bot-builder.html
MIT License
1.84k stars 252 forks source link

Feat/generate fb message #8

Closed stojanovic closed 8 years ago

stojanovic commented 8 years ago

Adds generator for FB templates.

Options:

new fbTemplate.generic() // Generic template
new fbTemplate.buttons() // Buttons template
new fbTemplate.receipt() // Receipt template
new fbTemplate.image()   // Image attachment

Usage:

const fbTemplate = require('claudia-bot-builder').formatFbMessage

let message = new fbTemplate.generic()
  .addBubble('1', 'hello')
    .addUrl('http://google.com')
  .addBubble('2', 'hello')
    .addImage('http://path.to/some/image.png')
  .addBubble('3', 'hello')
    .addButton('Button 1', 'postback value')
    .addButton('Button 2', 'http://google.com')
  .get();

console.log(JSON.stringify(message));
/*
Output:

{  
  "attachment":{  
    "type":"template",
    "payload":{  
      "template_type":"generic",
      "elements":[  
        {  
          "title":"1",
          "subtitle":"hello",
          "item_url":"http://google.com"
        },
        {  
          "title":"2",
          "subtitle":"hello",
          "image_url":"http://path.to/some/image.png"
        },
        {  
          "title":"3",
          "subtitle":"hello",
          "buttons":[  
            {  
              "title":"Button 1",
              "type":"postback",
              "payload":"postback value"
            },
            {  
              "title":"Button 2",
              "type":"web_url",
              "url":"http://google.com"
            }
          ]
        }
      ]
    }
  }
}
*/
simalexan commented 8 years ago

@stojanovic looking good