<commit_before>// dependencies
var _ = require('lomath');
var app = require(__dirname + '/../index.js')

// API as superclass that bot inherits methods from
var API = require('telegram-bot-bootstrap')
var TradingAPI = require(__dirname + '/trading_api.js')
var AccountsAPI = require(__dirname + '/accounts_api.js')
// TODO: replace by a persistent storage like mongo
var tokens = {}

// The bot object prototype
// bot extends and inherits methods of API
var bot = function(token, webhookUrl) {
    API.apply(this, arguments);
    var self = this;
    // set webhook on construction: override the old webhook
    this.setWebhook(webhookUrl || '');
    this.tradingAPI = new TradingAPI();
    this.accountsAPI = new AccountsAPI();
    this.tradingAPI.on("Connected", function () {
        self.sendMessage(self.currentChatId, "Open API Connected");
    });
    this.tradingAPI.on("AUTH_RES", function() {
        self.sendMessage(self.currentChatId, "Authenticated");
        self.tradingAPI.sendSubscribeForSpotsRequest(188328, "EURUSD", tokens[self.currentChatId]);
    });
    this.tradingAPI.on("OA_SPOT_EVENT", function (msg) {
        self.sendMessage(self.currentChatId, msg.symbolName + ', Bid: ' + msg.bidPrice + ', Ask: ' + msg.askPrice);
    });
    this.tradingAPI.init();
}

// set prototype to API
bot.prototype = API.prototype;
// set constructor back to bot
bot.prototype.constructor = bot;

/**
 * Handles a Telegram Update object sent from the server. Extend this method for your bot.
 *
 * @category Bot
 * @param {Object} req The incoming HTTP request.
 * @param {Object} res The HTTP response in return.
 * @returns {Promise} promise A promise returned from calling Telegram API method(s) for chaining.
 *
 * @example
 * var bot1 = new bot('yourtokenhere');
 * ...express server setup
 * app.route('/')
 * // robot API as middleware
 * .post(function(req, res) {
 *     bot1.handle(req, res)
 * })
 * // Then bot will handle the incoming Update from you, routed from Telegram!
 *
 */
bot.prototype.handle = function(req, res) {
    var self = this;
    // the Telegram Update object. Useful shits
    var Update = req.body,
        // the telegram Message object
        Message = Update.message,
        // the user who sent it
        userId = Message.from.id,
        // id of the chat(room)
        chatId = Message.chat.id;

    ////////////////////////
    // Extend from here:  //
    ////////////////////////
    // you may call the methods from API.js, which are all inherited by this bot class

    // echo
    if (Message.text == "/start") {
        var token = tokens[chatId];
        if (!token) {
            this.sendMessage(chatId, "Please authenticate your cTrader ID: https://ctrader-telegram-bot.herokuapp.com/auth?state=" + chatId);
        }
        this.currentChatId = Message.chat.id;
    }
    if (Message.text == "/stop") {
        this.tradingAPI.destroy();
    }
    if (Message.text == "/auth") {
        this.sendMessage(chatId, "https://ctrader-telegram-bot.herokuapp.com/auth?state=" + chatId);
    }
    if (Message.text == "/accounts") {
        this.accountsAPI.getTradingAccounts(tokens[chatId].token.access_token,
            function (error, result) {
                if (error) {
                    console.log('Get Trading Accounts Error', error.message);
                } else {
                    app.render('accounts', result, function(err, message) {
                        console.log("err= " + err);
                        console.log("message= " + message);
                        self.sendMessage(chatId, message);
                    });
                }
            });
    }
    this.sendMessage(chatId, "you said: " + Message.text);
}

bot.prototype.saveToken = function(token, state) {
    this.sendMessage(state, "Authenticated successfully");
    tokens[state] = token;
}

// export the bot class
module.exports = bot;

// sample keyboard
var kb = {
    keyboard: [
        ['one', 'two'],
        ['three'],
        ['four']
    ],
    one_time_keyboard: true
}
<commit_msg>Added formatting of accounts list<commit_after>// dependencies
var _ = require('lomath');
var app = require(__dirname + '/../index.js')

// API as superclass that bot inherits methods from
var API = require('telegram-bot-bootstrap')
var TradingAPI = require(__dirname + '/trading_api.js')
var AccountsAPI = require(__dirname + '/accounts_api.js')
// TODO: replace by a persistent storage like mongo
var tokens = {}

// The bot object prototype
// bot extends and inherits methods of API
var bot = function(token, webhookUrl) {
    API.apply(this, arguments);
    var self = this;
    // set webhook on construction: override the old webhook
    this.setWebhook(webhookUrl || '');
    this.tradingAPI = new TradingAPI();
    this.accountsAPI = new AccountsAPI();
    this.tradingAPI.on("Connected", function () {
        self.sendMessage(self.currentChatId, "Open API Connected");
    });
    this.tradingAPI.on("AUTH_RES", function() {
        self.sendMessage(self.currentChatId, "Authenticated");
        self.tradingAPI.sendSubscribeForSpotsRequest(188328, "EURUSD", tokens[self.currentChatId]);
    });
    this.tradingAPI.on("OA_SPOT_EVENT", function (msg) {
        self.sendMessage(self.currentChatId, msg.symbolName + ', Bid: ' + msg.bidPrice + ', Ask: ' + msg.askPrice);
    });
    this.tradingAPI.init();
}

// set prototype to API
bot.prototype = API.prototype;
// set constructor back to bot
bot.prototype.constructor = bot;

/**
 * Handles a Telegram Update object sent from the server. Extend this method for your bot.
 *
 * @category Bot
 * @param {Object} req The incoming HTTP request.
 * @param {Object} res The HTTP response in return.
 * @returns {Promise} promise A promise returned from calling Telegram API method(s) for chaining.
 *
 * @example
 * var bot1 = new bot('yourtokenhere');
 * ...express server setup
 * app.route('/')
 * // robot API as middleware
 * .post(function(req, res) {
 *     bot1.handle(req, res)
 * })
 * // Then bot will handle the incoming Update from you, routed from Telegram!
 *
 */
bot.prototype.handle = function(req, res) {
    var self = this;
    // the Telegram Update object. Useful shits
    var Update = req.body,
        // the telegram Message object
        Message = Update.message,
        // the user who sent it
        userId = Message.from.id,
        // id of the chat(room)
        chatId = Message.chat.id;

    ////////////////////////
    // Extend from here:  //
    ////////////////////////
    // you may call the methods from API.js, which are all inherited by this bot class

    // echo
    if (Message.text == "/start") {
        var token = tokens[chatId];
        if (!token) {
            this.sendMessage(chatId, "Please authenticate your cTrader ID: https://ctrader-telegram-bot.herokuapp.com/auth?state=" + chatId);
        }
        this.currentChatId = Message.chat.id;
    }
    if (Message.text == "/stop") {
        this.tradingAPI.destroy();
    }
    if (Message.text == "/auth") {
        this.sendMessage(chatId, "https://ctrader-telegram-bot.herokuapp.com/auth?state=" + chatId);
    }
    if (Message.text == "/accounts") {
        this.accountsAPI.getTradingAccounts(tokens[chatId].token.access_token,
            function (error, result) {
                if (error) {
                    console.log('Get Trading Accounts Error', error.message);
                } else {
                    console.log(result);
                    app.render('accounts', result, function(err, message) {
                        console.log("err= " + err);
                        console.log("message= " + message);
                        self.sendMessage(chatId, message);
                    });
                }
            });
    }
    this.sendMessage(chatId, "you said: " + Message.text);
}

bot.prototype.saveToken = function(token, state) {
    this.sendMessage(state, "Authenticated successfully");
    tokens[state] = token;
}

// export the bot class
module.exports = bot;

// sample keyboard
var kb = {
    keyboard: [
        ['one', 'two'],
        ['three'],
        ['four']
    ],
    one_time_keyboard: true
}

{'fraction_non_alphanumeric': 0.14238532110091742, 'fraction_numerical': 0.0019571865443425078, 'mean_word_length': 2.3967594515995017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '555522', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2370, 'n_words': 639}