New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bot-messenger-node

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bot-messenger-node - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6-beta

webhook/index.js

11

index.js

@@ -1,6 +0,7 @@

const AttachmentUploadApi = require('./lib/attachment_upload');
const ProfileApi = require('./lib/messenger_profile');
const SendApi = require('./lib/send_api');
const {AttachmentUploadApi} = require('./lib/attachment_upload');
const {ProfileApi} = require('./lib/messenger_profile');
const {SendApi} = require('./lib/send_api');
const { API_VERSION } = require('./lib/constants');
const outils= require('./lib/components');
const {Webhook}= require("./webhook")
module.exports = {

@@ -11,2 +12,4 @@ AttachmentUploadApi,

API_VERSION,
outils:outils,
Webhook
};

@@ -7,3 +7,3 @@ const axios = require('axios');

class AttachmentUploadApi {
class AttachmentsendApi {
constructor(pageAccessToken) {

@@ -27,35 +27,35 @@ this.graphVersion = API_VERSION;

uploadRemoteImage(imageUrl) {
return this.uploadRemoteAttachment('image', imageUrl);
sendRemoteImage(imageUrl) {
return this.sendRemoteAttachment('image', imageUrl);
}
uploadRemoteVideo(videoUrl) {
return this.uploadRemoteAttachment('video', videoUrl);
sendRemoteVideo(videoUrl) {
return this.sendRemoteAttachment('video', videoUrl);
}
uploadRemoteAudio(audioUrl) {
return this.uploadRemoteAttachment('audio', audioUrl);
sendRemoteAudio(audioUrl) {
return this.sendRemoteAttachment('audio', audioUrl);
}
uploadRemoteFile(fileUrl) {
return this.uploadRemoteAttachment('file', fileUrl);
sendRemoteFile(fileUrl) {
return this.sendRemoteAttachment('file', fileUrl);
}
uploadLocalImage(imageLocation) {
return this.uploadLocalAttachment('image', imageLocation);
sendLocalImage(imageLocation) {
return this.sendLocalAttachment('image', imageLocation);
}
uploadLocalVideo(videoLocation) {
return this.uploadLocalAttachment('video', videoLocation);
sendLocalVideo(videoLocation) {
return this.sendLocalAttachment('video', videoLocation);
}
uploadLocalAudio(audioLocation) {
return this.uploadLocalAttachment('audio', audioLocation);
sendLocalAudio(audioLocation) {
return this.sendLocalAttachment('audio', audioLocation);
}
uploadLocalFile(fileLocation) {
return this.uploadLocalAttachment('file', fileLocation);
sendLocalFile(fileLocation) {
return this.sendLocalAttachment('file', fileLocation);
}
async uploadLocalAttachment(assetType, fileLocation) {
async sendLocalAttachment(assetType, fileLocation) {
const mimetype = fileLocation.endsWith('.pdf') ? 'application/octet-stream' : 'image/png';

@@ -83,3 +83,3 @@

async uploadRemoteAttachment(assetType, fileUrl) {
async sendRemoteAttachment(assetType, fileUrl) {
const requestBody = {

@@ -100,2 +100,3 @@ message: {

}
}
}
module.exports={AttachmentsendApi};

@@ -8,7 +8,7 @@ const { ButtonType } = require('./constants');

addElement(element) {
add_element(element) {
this.elements.push(element);
}
getContent() {
get_content() {
return this.elements;

@@ -18,187 +18,221 @@ }

class Element {
constructor(title = "An element of a generic message.", subtitle = null, image_url = null, buttons = []) {
// Validate input types
if (typeof title !== 'string') {
throw new Error(`Type of param title must be string, not ${typeof title}`);
}
constructor(title = "An element of a generic message.", subtitle = null, image_url = null, buttons = []) {
// Validate input types
if (typeof title !== 'string') {
throw new Error(`Type of param title must be string, not ${typeof title}`);
}
if (title === "") {
throw new Error("Param title must be non-empty");
}
if (title === "") {
throw new Error("Param title must be non-empty");
}
this.__title = title;
this.__subtitle = subtitle;
this.__image_url = image_url;
this.__buttons = buttons || [];
this.__title = title;
this.__subtitle = subtitle;
this.__image_url = image_url;
this.__buttons = buttons || [];
if (this.__image_url === null || this.__buttons.length === 0) {
console.warn("WARNING: Param image_url and buttons must be non-empty.");
}
}
if (this.__image_url === null || this.__buttons.length === 0) {
console.warn("WARNING: Param image_url and buttons must be non-empty.");
}
}
set_title(title) {
if (typeof title !== 'string') {
throw new Error(`Type of param title must be string, not ${typeof title}`);
}
set_title(title) {
if (typeof title !== 'string') {
throw new Error(`Type of param title must be string, not ${typeof title}`);
}
if (title === "") {
throw new Error("Param title must be non-empty");
}
if (title === "") {
throw new Error("Param title must be non-empty");
}
this.__title = title;
}
this.__title = title;
}
set_subtitle(subtitle) {
if (typeof subtitle !== 'string') {
throw new Error(`Type of param subtitle must be string, not ${typeof subtitle}`);
}
set_subtitle(subtitle) {
if (typeof subtitle !== 'string') {
throw new Error(`Type of param subtitle must be string, not ${typeof subtitle}`);
}
this.__subtitle = subtitle;
}
this.__subtitle = subtitle;
}
set_image_url(image_url) {
if (typeof image_url !== 'string') {
throw new Error(`Type of param image_url must be string, not ${typeof image_url}`);
}
set_image_url(image_url) {
if (typeof image_url !== 'string') {
throw new Error(`Type of param image_url must be string, not ${typeof image_url}`);
}
this.__image_url = image_url;
}
this.__image_url = image_url;
}
add_button(button) {
if (!button || typeof button !== 'object') {
throw new Error(`Type of param button must be object, not ${typeof button}`);
}
add_button(button) {
if (!button || typeof button !== 'object') {
throw new Error(`Type of param button must be object, not ${typeof button}`);
}
this.__buttons.push(button);
}
this.__buttons.push(button);
}
get_content() {
if (this.__subtitle === null) {
return {
title: this.__title,
image_url: this.__image_url,
buttons: this.__buttons
};
}
get_content() {
if (this.__subtitle === null) {
return {
title: this.__title,
image_url: this.__image_url,
buttons: this.__buttons
};
}
return {
title: this.__title,
subtitle: this.__subtitle,
image_url: this.__image_url,
buttons: this.__buttons
};
}
return {
title: this.__title,
subtitle: this.__subtitle,
image_url: this.__image_url,
buttons: this.__buttons
};
}
}
class Buttons {
/**
* A list of Button objects.
* @constructor
*/
constructor() {
this.__buttons = [];
}
/**
* Add a Button object's content to the list.
* @param {object} button - The content of the Button object.
*/
add_button(button) {
if (!button || typeof button !== 'object') {
throw new Error(`Type of param button must be object, not ${typeof button}`);
}
this.__buttons.push(button);
}
get_content() {
return this.__buttons;
}
}
class Button {
constructor(button_type = ButtonType.POSTBACK, title = "Button") {
this.__type = button_type;
this.__title = title;
if (this.__type === ButtonType.POSTBACK) {
this.__payload = "<DEVELOPER_DEFINED_PAYLOAD>";
} else if (this.__type === ButtonType.WEB_URL) {
this.__url = "<DEVELOPER_DEFINED_URL>";
}
}
set_title(title) {
this.__title = title;
}
set_payload(payload) {
this.__payload = payload;
}
set_url(url) {
this.__url = url;
}
get_content() {
if (this.__type === ButtonType.POSTBACK) {
return {
"type": this.__type,
"title": this.__title,
"payload": this.__payload
};
}
return {
"type": this.__type,
"title": this.__title,
"url": this.__url
};
}
constructor(button_type = ButtonType.POSTBACK, title = "Button") {
this.__type = button_type;
this.__title = title;
if (this.__type === ButtonType.POSTBACK) {
this.__payload = "<DEVELOPER_DEFINED_PAYLOAD>";
} else if (this.__type === ButtonType.WEB_URL) {
this.__url = "<DEVELOPER_DEFINED_URL>";
}
}
set_title(title) {
this.__title = title;
}
set_payload(payload) {
this.__payload = payload;
}
set_url(url) {
this.__url = url;
}
get_content() {
if (this.__type === ButtonType.POSTBACK) {
return {
"type": this.__type,
"title": this.__title,
"payload": this.__payload
};
}
return {
"type": this.__type,
"title": this.__title,
"url": this.__url
};
}
}
class QuickReplies {
constructor() {
this.__quick_replies = [];
}
add_quick_reply(quick_reply) {
this.__quick_replies.push(quick_reply);
}
get_content() {
return this.__quick_replies;
}
constructor() {
this.__quick_replies = [];
}
add_quick_reply(quick_reply) {
this.__quick_replies.push(quick_reply);
}
get_content() {
return this.__quick_replies;
}
}
class QuickReply {
constructor(title = "Quick reply", payload = "<DEVELOPER_DEFINED_PAYLOAD>", image_url) {
this.__title = title;
this.__payload = payload;
this.__image_url = image_url;
}
set_title(title) {
this.__title = title;
}
set_payload(payload) {
this.__payload = payload;
}
set_image_url(image_url) {
this.__image_url = image_url;
}
get_content() {
if (this.__image_url === null) {
return {
"content_type": "text",
"title": this.__title,
"payload": this.__payload
};
}
return {
"content_type": "text",
"title": this.__title,
"payload": this.__payload,
"image_url": this.__image_url
};
}
constructor(title = "Quick reply", payload = "<DEVELOPER_DEFINED_PAYLOAD>", image_url) {
this.title = title;
this.payload = payload;
this.image_url = image_url;
}
set_title(title) {
this.title = title;
}
set_payload(payload) {
this.payload = payload;
}
set_image_url(image_url) {
this.image_url = image_url;
}
get_content() {
if (this.image_url === null) {
return {
"content_type": "text",
"title": this.title,
"payload": this.payload
};
}
return {
"content_type": "text",
"title": this.title,
"payload": this.payload,
"image_url": this.image_url
};
}
}
class PersistentMenu {
constructor(default_locale_menu) {
this.__persistent_menus = [
{
"locale": "default",
"composer_input_disabled": "false",
"call_to_actions": default_locale_menu
}
];
}
add_locale(language_code, menu) {
this.__persistent_menus.push({
"locale": language_code,
"composer_input_disabled": "false",
"call_to_actions": menu
});
}
get_content() {
return this.__persistent_menus;
}
}
constructor(default_locale_menu) {
this.__persistent_menus = [
{
"locale": "default",
"composer_input_disabled": "false",
"call_to_actions": default_locale_menu
}
];
}
add_locale(language_code, menu) {
this.__persistent_menus.push({
"locale": language_code,
"composer_input_disabled": "false",
"call_to_actions": menu
});
}
get_content() {
return this.__persistent_menus;
}
}
module.exports = {
Elements,
Element,
Button,
Buttons,
QuickReplies,
QuickReply,
PersistentMenu
};

@@ -1,2 +0,2 @@

const API_VERSION = "16.0";
const API_VERSION = "18.0";

@@ -3,0 +3,0 @@ class ButtonType {

@@ -66,2 +66,2 @@ const axios = require('axios');

module.exports = ProfileApi;
module.exports = {ProfileApi};

@@ -6,3 +6,3 @@ const axios = require('axios');

constructor(page_access_token, page_id = null) {
this.__graph_version = '16.0';
this.__graph_version = '18.0';
this.__def_api_url = `https://graph.facebook.com/v${this.__graph_version}/me`;

@@ -39,3 +39,3 @@ this.__alt_api_url = page_id === null ? null : `https://graph.facebook.com/v${this.__graph_version}/${page_id}`;

send_text(message, recipient_id, messaging_type = 'RESPONSE', notification_type = 'REGULAR', kwargs) {
send_text(message, recipient_id, messaging_type = 'RESPONSE', notification_type = 'REGULAR', kwargs=null) {
const request_body = {

@@ -99,8 +99,7 @@ messaging_type: messaging_type,

}
return requests.post(this.get_def_api_url() + this.get_def_endpoint(), {
return axios.post(this.get_def_api_url() + this.get_def_endpoint(),request_body, {
params: {
access_token: this.get_access_token()
},
json: request_body
}).json();
});
}

@@ -136,8 +135,7 @@

};
return requests.post(this.get_def_api_url() + this.get_def_endpoint(), {
return axios.post(this.get_def_api_url() + this.get_def_endpoint(),request_body, {
params: {
access_token: this.get_access_token()
},
json: request_body
}).json();
}
});
}

@@ -157,10 +155,9 @@

return requests.post(
this.get_alt_api_url() + this.get_def_endpoint(),
return axios.post(
this.get_alt_api_url() + this.get_def_endpoint(),request_body,
{
params: {
access_token: this.get_access_token()
},
json: request_body
}).json();
}
});
}

@@ -183,14 +180,13 @@

return requests.post(
this.get_def_api_url() + this.get_def_endpoint(),
return axios.post(
this.get_def_api_url() + this.get_def_endpoint(),request_body,
{
params: {
access_token: this.get_access_token()
},
json: request_body
}).json();
}
})
}
__send_local(asset_type, file_location, recipient_id, is_reusable = "true", mimetype = null) {
// Implement logic for determining mimetype
console.log(mimetype);

@@ -215,5 +211,5 @@

return requests.post(
return axios(
this.get_def_api_url() + this.get_def_endpoint(),
{
{method:"POST",
params: {

@@ -243,12 +239,28 @@ access_token: this.get_access_token()

return requests.post(
this.get_def_api_url() + this.get_def_endpoint(),
return axios.post(
this.get_def_api_url() + this.get_def_endpoint(),request_body,
{
params: {
access_token: this.get_access_token()
},
json: request_body
}).json();
}
})
}
async send_quick_replies(recipientId, quickReplies,messageText="Choose options: ") {
const messageData = {
recipient: {
id: recipientId,
},
message: {
text: messageText,
quick_replies: quickReplies
},
};
return await axios(this.__def_api_url+"/messages",
{method:"POST",
params: {
access_token: this.get_access_token()
},data:messageData});
}
send_batch_image(image_urls, recipient_id) {

@@ -283,3 +295,3 @@ if (this.get_page_id() === null) {

return requests.post(
return axios.post(
`https://graph.facebook.com/${this.get_graph_version()}`,

@@ -290,7 +302,7 @@ {

},
json: request_body
}).json();
request_body
});
}
}
module.exports = SendApi;
module.exports = {SendApi};
{
"name": "bot-messenger-node",
"version": "1.0.5",
"description": "A Node.js library streamlining the integration and smooth utilization of the Messenger API for the development of interactive chatbots.",
"version": "1.0.6-beta",
"description": "A Node.js toolkit facilitating the seamless incorporation and effective deployment of the Messenger API in crafting responsive chatbots.",
"main": "index.js",

@@ -25,3 +25,9 @@ "scripts": {

},
"homepage": "https://github.com/laza-niaina/bot-messenger-node#readme"
"homepage": "https://github.com/laza-niaina/bot-messenger-node#readme",
"dependencies": {
"axios": "^0.21.1",
"fs": "^0.0.1-security",
"assert": "^2.0.0",
"form-data": "^4.0.0"
}
}
# bot-messenger-node
[![npm version](https://img.shields.io/npm/v/bot-messenger-node.svg?style=flat)](https://www.npmjs.com/package/bot-messenger-node)
[![NPM

@@ -11,3 +12,3 @@ downloads](https://img.shields.io/npm/dm/bot-messenger-node.svg?style=flat)](https://www.npmjs.com/package/bot-messenger-node)

### Send API (v16.0)
### Send API (v18.0)
- Send text messages

@@ -19,3 +20,3 @@ - Send attachments from a remote file (image, audio, video, file)

- Send buttons
### Profile API (v16.0)
### Profile API (v18.0)
- Set welcome screen

@@ -51,5 +52,3 @@ - Set persistent menu

sendApi.sendTextMessage(message, recipientId)
.then(response => console.log(response))
.catch(error => console.error(error));
sendApi.send_text(message, recipientId)

@@ -73,10 +72,8 @@ ```

const button = new Button(POSTBACK, "My button");
buttons.addButton(button.getContent());
buttons.add_button(button.getContent());
const element = new Element("My element", "The element's subtitle", '<image_url>', buttons.getContent());
elements.addElement(element.getContent());
const element = new Element("My element", "The element's subtitle", '<image_url>', buttons.get_content());
elements.add_element(element.getContent());
sendApi.sendGenericMessage(elements.getContent(), '<recipient_id>', { image_aspect_ratio: "horizontal" })
.then(response => console.log(response))
.catch(error => console.error(error));
sendApi.send_generic(elements.getContent(), '<recipient_id>')

@@ -91,49 +88,15 @@ ```

// To send an image
sendApi.sendImageAttachment('<image_url>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
sendApi.send_image('<image_url>', '<recipient_id>')
// To send an audio
sendApi.sendAudioAttachment('<audio_url>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
sendApi.send_audio('<audio_url>', '<recipient_id>')
// To send a video
sendApi.sendVideoAttachment('<video_url>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
sendApi.send_video('<video_url>', '<recipient_id>')
// To send a file
sendApi.send_file('<file_url>', '<recipient_id>')
// To send a file
sendApi.sendFileAttachment('<file_url>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
```
##### Sending local image/audio/video/file:
```javascript
const SendApi = require('bot-messenger-node');
const sendApi = new SendApi('<page_access_token>');
// To send an image
sendApi.sendLocalImage('<image_location>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
// To send an audio
sendApi.sendLocalAudio('<audio_location>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
// To send a video
sendApi.sendLocalVideo('<video_location>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
// To send a file
sendApi.sendLocalFile('<file_location>', '<recipient_id>')
.then(response => console.log(response))
.catch(error => console.error(error));
```
## To do
- Securing requests
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc