Connecting Heroku Webhooks with Discord - node.js

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!

Related

MessageBird Whatsapp Spam Messages

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.

How to receive Discord.js interactions though POST requests at my endpoint

I am creating a Discord Bot using Discord.js and want to change it to receive interactions through POST requests instead of websockets, as the new option for Discord Apps:
You can optionally configure an interactions endpoint to receive interactions via HTTP POSTs rather than over Gateway with a bot user.
Slash commands and interactions works as expected with websocks by using:
client.ws.on('INTERACTION_CREATE', async (interaction) => {
// receive and answer the interaction
})
The problem is, I can't find on the documentation how to explicitly receive interactions through http POST neither options to set the listening PORT.

Why slack slash command returns "http_client_error"

I'm trying to build a very simple Slackbot using the Bolt Framework. I'm using ngrok to run this locally and when I invoke a slash command, ngrok just shows:
According to the Bot documentation, the app uses app.command() to handle slash commands. This is part of my code:
const {App, LogLevel} = require("#slack/bolt");
const app = new App({
token: "XXXX",
signingSecret: "XXXX",
logLevel: LogLevel.DEBUG
});
// The echo command simply echoes on command
app.command("/standup", async ({command, ack, say}) => {
// Acknowledge command request
ack();
say(`${command.text}`);
console.log("Entered into the app.command for /standUp");
});
Within Slack, the slash command is configured like this:
The bot works when interacting with messages, but just does receive and respond to Slash commands. I'm really new to this so any info would be great or just a push in the right direction.
I was able to figure out what the issue was. When I was trying above, I had the request url end with ../command, but it needed to stay the same as the configuration for Event Subscriptions with ../slack/events/.
I started to receive the commands after I made this change. As far as I can tell, this was not documented very well on Slack's docs, but I figured out the issue by seeing the configuration here and lots of trial and error. :)

How do I send form data from the client side to the server

So. I have a form that is supposed to send username and password to server when it's submitted. I have searched the web, and all of them were for sending data from client to other servers(like an api). What I want is to send data to the server that is hosting the client from the client. I have tried using websockets, but they get in the way of a different part of the code. Does anyone know how to do this?
loginForm.addEventListener('submit', e => {
e.preventDefault()
var f = new FormData()
f.set('usrnm', document.getElementById('loginUsername'))
f.set('psw', document.getElementById('loginPassword'))
})
Do you have any code written for it already? There are tons of examples online, what are some of the articles you've read that didn't answer your question. regardless you will need to make a POST request to your back end. Depending on your server side language you'll need to handle that request differently but they are normally your own API(endpoint).

How to send a message to all subscribed users with kik bot

I'm just a beginner trying to learn how to write a bot for kik.
I'm trying to write it with the node js framework that kik has provided.
I want to send a message to all subscribed users of the bot; I found this in their docs:
bot.send(Bot.Message.text('Hey, nice to meet you!'), 'a.username');
but I'm confused as to how they get the username of the subscribed user. I tried using bot.getUserProfile.username, but it seems to be undefined.
Thanks for any help! Also, any tips on how this bot works would be appreciated! I have no web development experience; why does this bot have to be on a server?
First of all, if you want to send a blast to all of your users, I'd recommend using the broadcast API, which allows you to send messages by batches of 100 (instead of 25 for the regular send() API).
You can use the broadcast API like this:
bot.broadcast(Bot.Message.text('some message'), ['username1', 'username2']);
Documentation for this method can be found here.
As for sending messages to all of your users, you will need to have a list of usernames somewhere (in a database, for example). At the moment, Kik does not provide a way to get your list of subscribers.
Something like this would work:
bot.use((msg, next) => {
let username = msg.from; // Find the username from the incoming message
registerInDatabase(username); // Save it somewhere
next(); // Keep processing the message
});
You will need to make sure that this is placed before you declare any other handler (such as bot.onTextMessage(), for instance).

Resources