<commit_before>/**
 * API wrapper for Messenger chatbot
 */

'use strict';

const request = require('request');
/**
 * @type {{Promise:object}}
 */
const es6Promise = require('es6-promise');
const Promise = es6Promise.Promise;

module.exports = function(token) {
	return {
		send: function(idSender, messageData) {
			return new Promise(function(resolve, reject) {
				console.log('Sending message ' + JSON.stringify(messageData));
				request({
					url: 'https://graph.facebook.com/v2.6/me/messages',
					qs: {access_token:token},
					method: 'POST',
					json: {
						recipient: {id:idSender},
						message: messageData,
					}
				}, 
				function(error, response, body) {
					if (error) {
						console.log('Error sending message: ', error);
						reject(error);
					} 
					else {
						if (response.body.error) {
							console.log(__filename + ' - send Error: ', response.body.error)
						}
						console.log('Message sent ' + JSON.stringify(messageData));
						resolve(response);
					}
				})
			});
		},

		sendTextMessage: function sendTextMessage(idSender, text) {
			let messageData = { text:text };
			return this.send(idSender, messageData);
		},
		
		sendPicMessage: function sendPicMessage(idSender, url) {
			return this.send(idSender, {<commit_msg>List template for details of offer<commit_after>/**
 * API wrapper for Messenger chatbot
 */

'use strict';

const request = require('request');
/**
 * @type {{Promise:object}}
 */
const es6Promise = require('es6-promise');
const Promise = es6Promise.Promise;

module.exports = function(token) {
	return {
		send: function(idSender, messageData) {
			return new Promise(function(resolve, reject) {
				console.log('Sending message ' + JSON.stringify(messageData));
				request({
					url: 'https://graph.facebook.com/v2.6/me/messages',
					qs: {access_token:token},
					method: 'POST',
					json: {
						recipient: {id:idSender},
						message: messageData,
					}
				}, 
				function(error, response, body) {
					if (error) {
						console.log('Error sending message: ', error);
						reject(error);
					} 
					else {
						if (response.body.error) {
							console.error(__filename + ' - send Error: ', response.body.error);
							console.trace();
						}
						console.log('Message sent ' + JSON.stringify(messageData));
						resolve(response);
					}
				})
			});
		},

		sendTextMessage: function sendTextMessage(idSender, text) {
			let messageData = { text:text };
			return this.send(idSender, messageData);
		},
		
		sendPicMessage: function sendPicMessage(idSender, url) {
			return this.send(idSender, {
{'fraction_non_alphanumeric': 0.14576923076923076, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 3.109004739336493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7353640', 'n_tokens_mistral': 1038, 'n_tokens_neox': 791, 'n_words': 168}