Pusher notifications client not acknowledging userId token - pusher

I'm trying to setup Pusher to receive push notifications from my server. I've gone through the docs and followed the instructions but I'm getting this error which I have no clue how to get past. If you help me sort it out it'll be like an early Christmas gift.
This is my client code:
const beamsClient = new PusherPushNotifications.Client({
instanceId: 'XXXXX-XXXX-XXXXX-XXXX',
});
const beamsTokenProvider = new PusherPushNotifications.TokenProvider({
url: "/Account/BeamsAuth/",
});
var currentUserId = `#User.Identity.GetUserId()`;
beamsClient.start()
.then(() => beamsClient.setUserId(currentUserId, beamsTokenProvider))
.then(() => beamsClient.addDeviceInterest('WaitingForRide'))
.then(() => beamsClient.getDeviceInterests())
.then((interests) => console.log("Current interests: ", interests))
.then(() => console.log('Successfully registered and subscribed!'))
.catch(console.error);
This is my server code:
This is the error I'm seeing on my browser's console:
TypeError: Cannot read properties of null (reading 'token')
at Client._callee14$ (push-notifications-cdn.js:2102)
at tryCatch (push-notifications-cdn.js:82)
at Generator.invoke [as _invoke] (push-notifications-cdn.js:308)
at Generator.prototype.<computed> [as next] (push-notifications-cdn.js:134)
at asyncGeneratorStep (push-notifications-cdn.js:770)
at _next (push-notifications-cdn.js:792)
The token acquisition process to create an Authenticated User is described here:
I'm positive that I've implemented the token acquisition process correctly but I can't seem to get past this error. It's a total curveball.
I'm really at a loss of what to do here. I tried researching this particular error but didn't get anything back on it. Any ideas are appreciated.

You should ensure the token is in JSON format, such as:
{"token":"XXXXXXXXX"}

Related

Firebase Messaging : canno't read property of undefined addEventListener

I created a Firebase App using NodeJS/VueJS and trying to setup Cloud Messaging.
I created a firebase-messaging-sw.js file, and added messaging on my main.js.
On my app I included firebase and on my mounted I did this (as stated on the doc) :
const messaging = firebase.messaging();
messaging.getToken({ vapidKey: "<KEY>" })
.then((currentToken) => {
if (currentToken) {
console.log('client token', currentToken)
} else {
console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
Then I am going to my webapp and I have the following error :
"Uncaught TypeError : cannot read property of undefined (reading 'addEventListener')"
This error kinda lost me since I don't know where does it come from.
When looking on the error I saw that :
Looking into the source register.ts it redirects me to this :
navigator.serviceWorker.addEventListener('message', e =>
messageEventListener(messaging as MessagingService, e));
But I don't understand the problem, I tried to describe as much as possible all the steps that leaded to the error. Even when I comment the code of my mounted I still have the error
Thanks in advance,

v11 TypeError: Cannot read properties of undefined (reading 'members') discord.js v11

I want to connect to discord voice channel with discord.js as a user, and it works on some accounts but there is one account that shows this error:
TypeError: Cannot read properties of undefined (reading 'members')
While using discord.js v11.
Here is my code:
const Discord = require('discord.js');
const client = new Discord.Client();
const channelId = process.env.id
client.on("ready", () => {
let channel = client.channels.cache.get(channelId);
if(!channel) return console.log("Invalid channel id");
channel.join().then(connection => {
console.log("Successfully connected");
});
});
client.login(process.env.token);
(this is the code)
i am using discord.js v11.3.2
For one, member doesn't show up anywhere in this code snippet, and you will need to add some more code. I also noticed that at the 2nd line, channelId is spelt wrong, so that will cause an error. If you extend your code, I might be able to help. I am assuming that members is supposed to be member. So, try replacing members with member.

Botkit Slackbot responds with 401 error every time

I'm trying to create a very simple Slack bot using botkit and Google App Engine, but for some reason I keep getting 401 errors any time I message the bot. The weird thing is that the Slack Event Subscription URL (the one ending in /api/messages) validates correctly, and I get a 200 response in GAE logs and validation within Slack.
But whenever I actually message the bot it always gets a 401 error with no message explaining the error at all. I've tried various combinations of the code below, and have now stripped it down to the bare minimum as found here. Aside from dependencies and a code to decrypt credentials (which I've verified is working as expected), this is my full code at the moment:
botInit();
async function botInit () {
const credentialsRaw = await getCredentials();
const credentials = JSON.parse(credentialsRaw);
const adapter = new SlackAdapter(credentials);
const controller = new Botkit({
adapter: adapter
});
controller.on('message', async(bot, message) => {
await bot.reply(message, 'I heard a message!');
});
}
I have also tried this for the messaging function:
controller.ready(() => {
controller.hears(['hello', 'hi'], ['message', 'direct_message'],
async (bot, message) => {
await bot.reply(message, 'Meow. :smile_cat:')
})
})
and this for setting up the controller:
const controller = new Botkit({
webhook_uri: '/api/messages',
adapter: adapter
});
And everything gives back the same exact 401 error, despite all of them working with the Event Subscription URL verification on Slack.
I had same issue but figured out the problem.
I had been using Client Secret as clientSigningSecret
But I should use Signing Secret !

Slack bot ALWAYS gives missing_scope error

I'm new to Slack bots so I went through their documentation and followed some tutorials on the internet but nothing seems to help. I'm trying to add a simple bot to a workspace I've just created, all I want is to make the bot post a message once it starts. Here is my code:
const SlackBot = require('slackbots');
const botToken = 'xoxp-XXXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXX'
const bots = async () => {
const bot = await new SlackBot({
token: botToken,
name: 'orderbot'
});
console.log('adding event listener...');
await bot.on('start', () => {
console.log('posting message...');
bot.postMessage('general', 'Feeling hungry?');
});
};
bots();
And in the OAuth & Permissions page, I've added ALL permissions to the token's scopes. Running the bot, here is my output:
adding event listener...
/home/mohammed/OrderBot/node_modules/vow/lib/vow.js:105
throw e;
^
Error: missing_scope
at /home/mohammed/OrderBot/node_modules/slackbots/index.js:46:33
So apparently, the error is coming from the .on listener which is quite confusing and I can't understand why this is happening. What exactly am I missing?
It seems like the module slackbots which I was using is not working properly (at least for me). I solved this issue by using #slack/web-api instead.

developing facebook messenger chatbot

I am trying to develop Facebook messenger chat bot. I have set my messenger and node server to talk with each other but when i try to send a message from messenger,after it reaches node server it tries to do merge action using node-wit library that in terms gives an error.
C:\Users\username\node_modules\node-wit\lib\wit.js:161
this.converse(
^
TypeError: Cannot read property 'converse' of undefined
at C:\Users\username\node_modules\node-wit\lib\wit.js:161:13
at Object.actions.say.merge (C:\Users\username\messenger.js:147:5)
at null. (C:\Users\username\node_modules\node-wit\lib\wit.js
:230:22)
at C:\Users\username\node_modules\node-wit\lib\wit.js:32:9
at process._tickCallback (node.js:355:11)
here is my code:
wit.runActions(
sessionId, // the user's current session
msg, // the user's message
sessions[sessionId].context, // the user's current session state
(error, context) => {
if (error) {
console.log('Oops! Got an error from Wit:', error);
} else {
// Our bot did everything it has to do.
// Now it's waiting for further messages to proceed.
console.log('Waiting for futher messages.');
// Updating the user's current session state
sessions[sessionId].context = context;
}
}
);
Try upgrading your node to version 6. It is a version related problem. Let me know if it works fine after upgrading.

Resources