'use strict';
var apiService = require('../apiService').getInstance();
var responsePayload = require('./responsePayload').getInstance();

function CategoryMenuResponse() {
    this._categories = apiService.getProductCategories();
}

CategoryMenuResponse.prototype = {
    getResponse: function () {
        var response = {
            attachment: {
                type: "template",
                payload: {
                    template_type: "button",
                    text: "What do you want to do next?",
                    buttons: []
                }
            }
        };

        if (this._categories !== undefined) {
            this._categories.forEach(function (category) {
                var newButton = {
                    type: "postback",
                    title: category.title,
                    payload: {
                        data: {
                            id: category.id
                        },
                        type: "category"
                    }
                };

                response.attachment.payload.buttons.push(newButton);
            });
        }
        console.info(response);
        return JSON.stringify(response);
    }
};

/**
 * @returns {CategoryMenuResponse}
 */
module.exports.getInstance = function () {
    return new CategoryMenuResponse();
};

@@ -825,32 +825,33 @@
       payload: %7B
+%7D
 %0A               
@@ -837,32 +837,42 @@
 d: %7B%7D%0A          
+      %7D;%0A%0A
               da
@@ -873,16 +873,69 @@
     
+  var payload = JSON.stringify(%7B%0A                    
 data: %7B%0A
     
@@ -926,32 +926,24 @@
     data: %7B%0A
-        
             
@@ -954,20 +954,23 @@
     
-id: category
+    id: product
 .id%0A
@@ -989,20 +989,16 @@
         
-    
 %7D,%0A     
@@ -1016,27 +1016,22 @@
     
- 
-   
 type: %22
-category
+product
 %22%0A  
@@ -1036,37 +1036,36 @@
                 
-    %7D
+%7D);%0A
 %0A               
@@ -1057,35 +1057,92 @@
                 
-%7D;%0A
+newButton.payload = Buffer.from(payload).toString('base64');
 %0A               

add product reponse