Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

custom payload outside of fulfillmentMessages array #12

Open
isbkch opened this issue Oct 27, 2018 · 0 comments
Open

custom payload outside of fulfillmentMessages array #12

isbkch opened this issue Oct 27, 2018 · 0 comments

Comments

@isbkch
Copy link

isbkch commented Oct 27, 2018

I've been trying to send back a normal text reply plus a Facebook's receipt template, but the template always ends up outside of the fulfillmentMessagespart of the JSON response.

I was not able to see the template so I checked in DialogFlow and it clearly sits outside of the fulfillmentMessages under unspecified. Any idea how that might happen?

My BE is in Lumen. The method that builds the response:

public function history()
    {
        $this->dialogAgent->reply('The following, ' . $this->user->first_name . ' is you order history');

        $history              = $this->user->getOrders();
        $historyReceipt = FacebookTemplates::receipt($history, $this->user);
        
        $this->dialogAgent->reply($historyReceipt);

        return response()->json($this->dialogAgent->render());
    }

And the method that build the receipt:

Public static function receipt($orders, $user)
    {
        $elements = [];
        foreach ($orders as $order) {
            $elements [] = [
                'title'     => 'Classic White T-Shirt',
                'subtitle'  => '100% Soft and Luxurious Cotton',
                'quantity'  => $order->quantity,
                'price'     => 50,
                'currency'  => 'USD',
                'image_url' => 'http://petersapparel.parseapp.com/img/whiteshirt.png',
            ];
        }

        return \Dialogflow\RichMessage\Payload::create([
            'attachment' => [
                'type'    => 'template',
                'payload' => [
                    'template_type'  => 'receipt',
                    'recipient_name' => 'My Name',
                    'summary'        => [
                        'subtotal'      => 400,
                        'shipping_cost' => 50,
                        'total_tax'      => 20,
                        'total_cost'    => 3334
                    ],
                    'elements' => $elements,
                ],
            ],
        ]);   
    }

Just putting dummy data in the template so far.

The template I'm trying to mimic is this one https://developers.facebook.com/docs/messenger-platform/send-messages/template/receipt

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

No branches or pull requests

1 participant