<commit_before>"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: <PASSWORD>['<PASSWORD>'],
    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);
});

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() }
}
<commit_msg>Push Notification Test<commit_after>"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: <PASSWORD>['<PASSWORD>'],
    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);

    sendProactiveMessage();
});

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() }
}

function sendProactiveMessage() {
    var address = {
        "id" : "mid.$cAAXXvCjTQUtkrQLNNFee72A56bn6",
        "channelId" : "facebook",
        "user" : {
            "id" : "1421609847955732",
            "name" : "<NAME>"
        },
        "conversation" : {
            "isGroup" : false,
            "id" : "1421609847955732-1644577435616203"
        },
        "bot" : {
            "id" : "1644577435616203",
            "name" : "bot-piloto-bncr"
        },
        "serviceUrl" : "https://facebook.botframework.com"
    };
    console.log('Ready to send');
    var msg = new builder.Message().address(address);
    msg.text('Hola, este es un push notification');
    msg.textLocale('en-US');
    bot.send(msg);
    console.log('Sent');
}
{'fraction_non_alphanumeric': 0.14836495761001212, 'fraction_numerical': 0.017561566410981024, 'mean_word_length': 3.2641996557659207, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462075', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1450, 'n_words': 308}