MessageBird Whatsapp Spam Messages - node.js

After making a basic conditional change in my code I started experiencing thousands of spam messages when testing the bot I've built.
Please do consider, in my code there is no loop whatsoever to trigger this process of spam messages.
Things Ive done to try to resolve the situation but did not work:
Comment the code to send messages to the client
Restarting the server
See below for my code
var checkContact = req.body.hasOwnProperty('contact');
var registerCustomer = {
name: '',
phoneNumber: ''
};
if (checkContact) {
registerCustomer.name = req.body.contact.displayName;
registerCustomer.phoneNumber = `+${req.body.contact.msisdn}`;
}
await messageBirdWhatsAppService.sendRegistrationMessage(registerCustomer.phoneNumber);
My question is:
Does Messagebird Whatsapp API requires a response status.
Are failed rejection of webhooks result into this issue.
Can fail responses (Returning a status to the server after making a call) cause this issue

This seemed to be a messagebird issue. As I deleted the channel of the WhatsApp chatbot and still messages was coming in. I'm still awaiting messagebird support response. So I will wait for confirmation before closing this.

This is now resolved, turns out even if a webhook is not called upon it still sends a request checking for the endpoint. In future, please ensure your endpoints are active. Hence the spam messages.

Related

Node telegram bot api - disable processing of updates sent before the bot starts

I, have this issue: when I start the bot it immediately starts looking for updates. However, in my particular case (especially during the developing) this can be very frustrating and uncomfortable. There is a way to tell the bot to process the update sent after the starting of the bot itself?
Thank you
You need to tell Telegram to "forget" those updates. This is how you would do it:
Send a request to: https://api.telegram.org/bot$TELEGRAM_TOKEN/getUpdates
Get the message_id of the last element (pop) of the result array
Send another request https://api.telegram.org/bot$TELEGRAM_TOKEN/getUpdates?offset=$OFFSET where $OFFSET is the message_id + 1
This is a stateless way of clearing pending requests. You can use curl,the browser or a request library (recommended) to do this. You can do this with node-telegram-bot-api but I don't recommend since you will have to create 2 bot instances, 1 polling and 1 non polling to clear the updates which is not a good practice since ntba doesn't decouple its methods in a different class.
So in pseudocode code:
const TOKEN = 'MY_TOKEN'
async function clearUpdates(token) {
const { result } = await request.get(`https://api.telegram.org/bot${token}/getUpdates`).json()
return await request.get(`https://api.telegram.org/bot${token}/getUpdates?offset=${result[result.length - 1].message_id + 1}`)
}
Now run clearUpdates before starting your bot.

Consuming error logs with Twilio API

I have developed an application that sends thousands of SMS using Twilio Notify Service.
const bindings = phoneNumbers.map(number =>
this.createBinding('sms', number)
);
await this.notifyService.notifications.create({
toBinding: bindings,
body
});
The code above doesn't give me a feedback of whether the messages were received or not, but as I can see in Twilio dashboard, some messages fail with error codes 30005, 30003, 30006 and 52001.
I'd like to consume all those error logs and unsubscribe the numbers with error codes. I'm thinking of creating a job that runs every night to do that.
I've tried to list all the alerts:
client.monitor.alerts.each(alert => {
console.log(alert.errorCode);
});
But it seems to fetch only some alerts with error code 52001.
How can I consume all the errors with Twilio API? Is there any other way to be notified of those errors?

Actions on Google - Handle Timeout

If the Action on Google times out, for whatever reason, there doesn't seem to be a notification/request message sent notifying the webhook of this.
On Alexa platform, a SessionEnded message is sent to the webhook.
How can I know if the assistant has timed out?
If you are using node.js in your webhook, you can use the app.catch-method. It is used to catch all unhandled errors and then it is possible to send an appropriate message. Here is an example:
app.catch((conv,error) => {
console.error(error);
conv.close("Oops, something went wrong. Our developers are trying to solve this as quickly as possible.");
})
Let me know if it worked.

Connecting Heroku Webhooks with Discord

I am trying to have updates to my heroku app sent to a Discord channel via webhook. However, the delivery attempts fail. I've double checked the Payload URL and it is correct. Not sure how to proceed from here.
Heroku's webhook format is not compatible with Discord so you can't just put a Discord webhook URL into Heroku. You need a middle-man server to receive events from Heroku, and construct and send corresponding messages to Discord.
Found this JS code, should work (change params variable and where it says webhook to your webhook url)
let x = new XMLHttpRequest();
x.open("POST", `<webhook link>`);
x.setRequestHeader('Content-type', 'application/json');
let params = {
username: "Webhook Bot",
content: "<message content as a string>"
}
x.send(JSON.stringify(params));
i should mention that to mention a channel instead of #channel-name you'll have to use <#channelid>, for example <#1234567890> instead of #foo-bar
(this is my first post, sorry if it's a bit bad)
Without being able to see your code and the request structure you are using it will be hard to determine where the issue is coming from exactly, but one thing you might what to check is how you are sending the JSON payload to the Discord webhook URL.
Discord does not seem to accept the request unless you specify that the body of the payload is JSON. I discovered this because of an application I am working on currently. I know this answer is coming significantly after the fact, but it might help someone else down the line!

Detecting Socket.IO message delivery error on client side

We need to update the client side UI to indicate that a message fails to deliver. How do I have Socket.IO JS client call a custom callback directly when the message fails to deliver? For example, something like:
socket.emit("event", data).onError(myCallback);
I know Socket.IO provides the Ack mechanism to confirm delivery success. Therefore, one can set up a timer with a handler which calls the failure callback, if the ack is not called after a certain amount of time. But this doesn't seem to be the best way to do.
Also there is the error event provided by Socket.IO, but it doesn't come with info regarding which emit caused the error.
Unfortunately there's no way to get errors from callbacks, the only way is to indeed create your own timeout:
var timeoutId = setTimeout(timeoutErrorFn, 500);
var acknCallbackFn = function(err, userData){
clearTimeout(timeoutId)
//manage UserData
}
socket.emit('getUserData', acknCallbackFn);
Source of the code
And there's another issue about this, open
So for the time being you have to stick with your manual setTimeout.

Resources