"use strict";

// External packages declaration
var apiairecognizer     = require('api-ai-recognizer'),
    builder             = require("botbuilder"),
    botbuilder_azure    = require("botbuilder-azure"),
    path                = require('path'),
    util                = require('util');

// Internal packages declaration
var middleware          = require('../libs/middleware'),
    poi                 = require('../libs/client_location_service');

// Environment variables load 
require('dotenv').config();

// Define if we are going to use emulator in local enviroment
var useEmulator = (process.env.NODE_ENV == 'development');

var connector = useEmulator ? new builder.ChatConnector() : new botbuilder_azure.BotServiceConnector({
    appId: process.env['MicrosoftAppId'],
    appPassword: process.env['MicrosoftAppPassword'],
    stateEndpoint: process.env['BotStateEndpoint'],
    openIdMetadata: process.env['BotOpenIdMetadata']
});

var bot = new builder.UniversalBot(connector);

bot.localePath(path.join(__dirname, './locale'));

bot.dialog('/Cancelar', [
    function (session) {
        session.endDialog('Cancelado el dialogo');
    }
]).triggerAction({ matches: /^cancelar/i});

var recognizer = new apiairecognizer(process.env['ApiAiToken']); 
var intents = new builder.IntentDialog({ recognizers: [recognizer] } )
.onDefault((session, args) => {
    var name = session.message.user ? session.message.user.name : null;
    session.send(name + ' ' + args.entities[0].entity);
});

// Add dialog to return list of shirts available
bot.dialog('showShirts', function (session) {
    var msg = new builder.Message(session);
    msg.attachmentLayout(builder.AttachmentLayout.carousel)
    msg.attachments([
        new builder.HeroCard(session)
            .title("Classic White T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/whiteshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic white t-shirt", "Buy")
            ]),
        new builder.HeroCard(session)
            .title("Classic Gray T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/grayshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic gray t-shirt", "Buy")
            ])
    ]);
    session.send(msg).endDialog();
}).triggerAction({ matches: /^(show|list)/i });

bot.dialog('/', intents);    

// Set the Incoming and Outcoming functions for the middleware
bot.use({
    botbuilder: middleware.LogIncomingMessage,
    send: middleware.LogOutgoingMessage
});

// Create the listening
if (useEmulator) {
    var restify = require('restify');
    var server = restify.createServer();
    server.listen(3978, function() {
        console.log('test bot endpoint at http://localhost:3978/api/messages');
    });
    server.post('/api/messages', connector.listen());    
} else {
    module.exports = { default: connector.listen() }
}



@@ -1498,1217 +1498,8 @@
 );%0A%0A
-// Add dialog to return list of shirts available%0Abot.dialog('showShirts', function (session) %7B%0A    var msg = new builder.Message(session);%0A    msg.attachmentLayout(builder.AttachmentLayout.carousel)%0A    msg.attachments(%5B%0A        new builder.HeroCard(session)%0A            .title(%22Classic White T-Shirt%22)%0A            .subtitle(%22100%25 Soft and Luxurious Cotton%22)%0A            .text(%22Price is $25 and carried in sizes (S, M, L, and XL)%22)%0A            .images(%5Bbuilder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/whiteshirt.png')%5D)%0A            .buttons(%5B%0A                builder.CardAction.imBack(session, %22buy classic white t-shirt%22, %22Buy%22)%0A            %5D),%0A        new builder.HeroCard(session)%0A            .title(%22Classic Gray T-Shirt%22)%0A            .subtitle(%22100%25 Soft and Luxurious Cotton%22)%0A            .text(%22Price is $25 and carried in sizes (S, M, L, and XL)%22)%0A            .images(%5Bbuilder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/grayshirt.png')%5D)%0A            .buttons(%5B%0A                builder.CardAction.imBack(session, %22buy classic gray t-shirt%22, %22Buy%22)%0A            %5D)%0A    %5D);%0A    session.send(msg).endDialog();%0A%7D).triggerAction(%7B matches: /%5E(show%7Clist)/i %7D);%0A%0A
 bot.

Fix Azure