Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
nubitel-whatsapp-api
Advanced tools
Readme
Based on the Whatsapp Platform Sample
npm i nubitel-whatsapp-api --save
See Setup for more details about setting up the bot/page.
const whatsappAPI = require("nubitel-whatsapp-api");
const whatsapp = new whatsappAPI().Messenger({
appId: "",
pageId: "",
analyticsLogLevel: "",
appSecret: "",
pageAccessToken: "",
validationToken: "",
});
var pageScopedUserID = "...";
whatsapp.getUserProfile(pageScopedUserID, (err, resp) => {
if (err) {
console.error(recipientId, "Sorry, looks like the backend is down :-(");
} else {
console.log(JSON.parse(resp));
}
});
whatsapp.sendTemplateMessage(pageScopeUserID, [
{
title: "Welcome to Peter's Hats",
image_url: "https://petersfancybrownhats.com/company_image.png",
subtitle: "We've got the right hat for everyone.",
default_action: {
type: "web_url",
url: "https://peterssendreceiveapp.ngrok.io/view?item=103",
whatsapp_extensions: true,
webview_height_ratio: "tall",
fallback_url: "https://peterssendreceiveapp.ngrok.io/",
},
buttons: [
{
type: "web_url",
url: "https://petersfancybrownhats.com",
title: "View Website",
},
{
type: "postback",
title: "Start Chatting",
payload: "DEVELOPER_DEFINED_PAYLOAD",
},
],
},
]);
The example folder contains a sample app
npm install
cd example
export MESSENGER_ANALYTICS_LOG_LEVEL = "2";
export MESSENGER_APP_ID = "--yours--";
export MESSENGER_PAGE_ID = "--yours--";
export MESSENGER_APP_SECRET="--yours--"
export MESSENGER_VALIDATION_TOKEN="--yours--"
export MESSENGER_PAGE_ACCESS_TOKEN="--yours--"
node server
Or use this in your existing code
const express = require("express");
var ignores = ["/some-url/to-ignore"];
var verifySignature = true;
const whatsappAPI = require("nubitel-whatsapp-api");
const whatsapp = new whatsappAPI().Messenger({
appId: "",
pageId: "",
analyticsLogLevel: "",
appSecret: "",
pageAccessToken: "",
validationToken: "",
});
const webhookHandler = new whatsappAPI().Webhook(
whatsapp,
{
receivedAuthentication: function (event) {
console.log("receivedAuthentication", event);
},
handleMessage: function (event) {
console.log("handleMessage", event);
whatsapp.sendTextMessage(event.sender.id, JSON.stringify(event));
},
receivedDeliveryConfirmation: function (event) {
console.log("receivedDeliveryConfirmation", event);
},
receivedPostback: function (event) {
console.log("receivedPostback", event);
},
receivedMessageRead: function (event) {
console.log("receivedMessageRead", event);
},
doLinking: function (event) {
console.log("doLinking", event);
},
doUnlinking: function (event) {
console.log("doUnlinking", event);
},
},
verifySignature,
ignores,
express.Router()
);
var app = express();
app.set("port", process.env.PORT || 3000);
app.use(express.static("public"));
app.use("/fb", webhookHandler);
app.listen(app.get("port"), function () {
console.log("Node app is running in http mode on port", app.get("port"));
});
You can now send analytics events through the following API (See App Events with Bots for Messenger - Logging Custom Events and App Events API for more details about the event types)
For performace reasons if you would like to throttle the events that you would like to send/track, you can use the env variable
export MESSENGER_ANALYTICS_LOG_LEVEL = "2";
to control the log levels. Set that to
Level | Value | Description |
---|---|---|
None | 99 | Don't send any analytics events |
Critical | 2 | Send only critical analytics events |
Verbose | 1 | Send all analytics events |
The asynchronous callback from the analyticsEvent call would be either
{
"success": true
}
if the event was successfully accepted or
{
"skip": true
}
if the event was skipped due lower log levels
whatsapp.analyticsEvent(
whatsappapi.ANALYTICS_LEVEL_VERBOSE,
event.sender.id,
() => {
return whatsapp.buildAnalyticsEvent("fb_mobile_verbose_event");
},
(err, resp) => {
whatsapp.sendTextMessage(event.sender.id, JSON.stringify(err ? err : resp));
}
);
whatsapp.analyticsEvent(
whatsappapi.ANALYTICS_LEVEL_CRITICAL,
event.sender.id,
() => {
return whatsapp.buildAnalyticsEvent("fb_mobile_purchase", { _valueToSum: 9.99, fb_currency: "USD" });
},
(err, resp) => {
whatsapp.sendTextMessage(event.sender.id, JSON.stringify(err ? err : resp));
}
);
whatsapp.quickAnalytics(whatsappapi.ANALYTICS_LEVEL_CRITICAL, event.sender.id, "fb_mobile_add_to_cart", {
fb_content_type: "blah blah blah",
fb_content_id: "123456789",
_valueToSum: 9.99,
fb_currency: "USD",
});
FAQs
Node.js Whatsapp API
The npm package nubitel-whatsapp-api receives a total of 1 weekly downloads. As such, nubitel-whatsapp-api popularity was classified as not popular.
We found that nubitel-whatsapp-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.