Eugene
Eugene

Reputation: 35

Bot framework V4 how to add facebook receipt with discount

Is it possible to use the Discount option from Facebook Messenger's Receipt Template with Bot Framework V4?

Because I tried searching the samples, but they require string values, while the Facebook Template requires arrays.

Example:

"adjustments":[
      {
        "name":"New Customer Discount",
        "amount":20
      },
      {
        "name":"$10 Off Coupon",
        "amount":10
      }
    ],

Upvotes: 0

Views: 96

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

Facebook Templates can be sent using ChannelData. Here is an example of a receipt template with adjustments:

await context.sendActivity({
     text: 'Receipt',
     channelData: {
            "attachment":{
                "type":"template",
                "payload": {
                    "template_type": "receipt",
                    "recipient_name": "Stephane Crozatier",
                    "order_number": "12345678902",
                    "currency": "USD",
                    "payment_method": "Visa 2345",
                    "order_url": "http://petersapparel.parseapp.com/order?order_id=123456",
                    "timestamp": "1428444852",
                    "address": {
                        "street_1": "1 Hacker Way",
                        "street_2": "",
                        "city": "Menlo Park",
                        "postal_code": "94025",
                        "state": "CA",
                        "country": "US"
                    },
                    "summary": {
                        "subtotal": 75.00,
                        "shipping_cost": 4.95,
                        "total_tax": 6.19,
                        "total_cost": 56.14
                    },
                    "adjustments": [{
                            "name": "New Customer Discount",
                            "amount": 20
                        },
                        {
                            "name": "$10 Off Coupon",
                            "amount": 10
                        }
                    ],
                    "elements": [{
                            "title": "Classic White T-Shirt",
                            "subtitle": "100% Soft and Luxurious Cotton",
                            "quantity": 2,
                            "price": 50,
                            "currency": "USD",
                            "image_url": "http://petersapparel.parseapp.com/img/whiteshirt.png"
                        },
                        {
                            "title": "Classic Gray T-Shirt",
                            "subtitle": "100% Soft and Luxurious Cotton",
                            "quantity": 1,
                            "price": 25,
                            "currency": "USD",
                            "image_url": "http://petersapparel.parseapp.com/img/grayshirt.png"
                        }
                    ]
                }
            }
     }
});

Upvotes: 1

Related Questions