Error thrown when trigger method called in pusher, "expected string" - node.js

I'm trying to configure pusher on my nodejs app.
const Pusher = require("pusher");
const pusher = new Pusher({
appId: "id",
key: "key",
secret: "secret",
cluster: "ap2",
useTLS: true,
});
pusher.trigger('my-channel', 'my-event', {
message: "Hello, world."
}).then(console.log).catch(e=> console.log(e))
When I put above code in index and run, I get following error message.
{
name: 'PusherRequestError',
message: 'Unexpected status code 400',
url: 'a URL with all secret and stuff',
error: undefined,
status: 400,
body: 'expected string\n'
}
I double-checked the keys, secrets, etc and they are all correct. Any help is appreciated. Thanks!

Related

how to fix errors like this "DiscordAPIError: Missing Access"

I followed the tutorial from youtube and I found an error like this and I don't know where the problem is. When i run node my_bot.js, Then there is an error DiscordAPIError: Missing Access.
I've tried a few things. My expectation will appear the words Hello World on discord. The result is an error.
I think, there is nothing wrong with my code
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on('ready', () => {
console.log("Connected as " + client.user.tag)
client.user.setActivity('you', { type: 'WATCHING' });
client.guilds.cache.forEach((guild) => {
console.log(guild.name);
guild.channels.cache.forEach((channel) => {
console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
})
// General channel id: 956453625889185826
})
let generalChannel = client.channels.cache.get("956453625889185826")
generalChannel.send("Hello World")
})
client.login("XXXXXXXXXXXXXXXXXXXXX")
Result:
Connected as Davd#3016
gavbot
- Text Channels GUILD_CATEGORY 956453625889185824
- Voice Channels GUILD_CATEGORY 956453625889185825
- general GUILD_TEXT 956453625889185826
- General GUILD_VOICE 956453625889185827
C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\User\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/956453625889185826/messages',
code: 50001,
httpStatus: 403,
requestData: {
json: {
content: 'Hello World',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
As the error says, Missing access means that your bot doesn't have the permissions to send a message in the channel.
Make sure your bot has the Send message permission in the channel you want to send the message

discord.js bot crashes after trying to send a message in a channel it can't send messages

Well discord.js bot crashes after trying to send a message in a channel it sees but can't send messages
well I get a crash after that, how can I fix this? here is the error it shows it shows for other commands too
/home/pi/Desktop/floppa_gaming/node_modules/discord.js/src/rest/RequestHandler.js:298
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/pi/Desktop/floppa_gaming/node_modules/discord.js/src/rest/RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/pi/Desktop/floppa_gaming/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async TextChannel.send (/home/pi/Desktop/floppa_gaming/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:171:15) {
method: 'post',
path: '/channels/785243249072930869/messages',
code: 50013,
httpStatus: 403,
requestData: {
json: {
content: 'You can use get help by saying "floppa help" in the chat :wink:',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
and if anyobody wants to see my terrible code here it is
const { Client, Intents, MessageEmbed, Permissions } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES,] });
var fs = require('fs');
var files = fs.readdirSync('./floppa/');
client.on('ready', () => {
client.user.setStatus('invisible') //You can set idle, dnd or invisible
client.user.setActivity("use floppa to get a image!", { type: 'PLAYING' }) // PLAYING , LISTENING , WATCHING , STREAMING
console.log("on discord lol");
});
const { AutoPoster } = require('topgg-autoposter')
const poster = AutoPoster('token', client) // tells topgg amount of servers ur bot is in
// optional
poster.on('posted', (stats) => { // ran when succesfully posted
console.log(`Posted stats to Top.gg | ${stats.serverCount} servers`)
})
client.on('message', msg => {
if (msg.content === 'floppa')
{
imageNumber = files[Math.floor(Math.random()*files.length)]
msg.channel.send ( {files: ["./floppa/" + imageNumber]} )
}
// finds a random image in a folder
The error shown is: DiscordAPIError: Missing Permissions
This means that your bot does not have permission to send messages in that channel. To avoid your bot crashing when this happens, you need to do one of the following:
Catch the error:
msg.channel.send("stuff").catch((err) => {/* handle errors */});
Verify that your bot has the permissions to post before posting:
if (msg.guild && msg.channel.permissionsFor(msg.guild.me).has("SEND_MESSAGES"))) {
msg.channel.send("stuff");
}

Access HashiCorp Vault KV secret using node-vault

I'm trying to access HashiCorp Vault KV with "node-vault" but keep getting "statusCode: 404"
I'm following the example of node-vault
https://github.com/kr1sp1n/node-vault
1) I'm running vault_1.1.3_windows_amd64 on windows 10 with "vault server -dev" on a PowerShell.
2) Then on another PowerShell runs following;
$env:VAULT_ADDR="http://127.0.0.1:8200"
vault secrets enable -version=1 kv
vault status
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed false
Total Shares 1
Threshold 1
Version 1.1.3
Cluster Name vault-cluster-28a041c6
Cluster ID 0ec85d70-8e87-dff6-347f-b1959fad8b44
HA Enabled false
3) Then runs the following code with the
const rootKey = //whatever;
const unsealKey = //whatever;
var options = {
apiVersion: 'v1',
endpoint: 'http://127.0.0.1:8200',
token: rootKey
};
var vault = require("node-vault")(options);
vault.unseal({ key: unsealKey })
.then(() => {
vault.write('secret/hello', { value: 'world' })
.then((res) => console.log(res))
.catch((err) => console.error(err));
});
vault.write('secret/hello', { value: 'world', lease: '1s' })
.then( () => vault.read('secret/hello'))
.then( () => vault.delete('secret/hello'))
.catch(console.error);
This return a status 404, what needs to be done additionally to avoid 404?
{ Error: Status 404
at handleVaultResponse (XX\TestCodes\Node-VaultTest\node_modules\node-vault\src\index.js:49:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
response:
{ statusCode: 404,
body:
{ request_id: '2992e6c2-5146-6569-1f48-55f75da88993',
lease_id: '',
renewable: false,
lease_duration: 0,
data: null,
wrap_info: null,
warnings: [Array],
auth: null } } }
{ Error: Status 404
at handleVaultResponse (XX\TestCodes\Node-VaultTest\node_modules\node-vault\src\index.js:49:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
response:
{ statusCode: 404,
body:
{ request_id: '2f280fa4-6596-c06f-2168-091246e0a2a1',
lease_id: '',
renewable: false,
lease_duration: 0,
data: null,
wrap_info: null,
warnings: [Array],
auth: null } } }
You mounted the kv store as a version 1. The actual path used by node-vault to read a secret from a version 2 kv store is different and not compatible with Vault's v1 kv store.
Mount your kv store with -version 2. If unspecified, it defaults to v1.
Also bear in mind that you need to add "data" to your path to get it working.
I for instance had kv/mySecret since "mySecret" was in the root "folder". Even though you need to add kv/data/mySecret. Then it worked for me!

NODEJS Marklogic - Write document list cannot process response with 404 status when using documents.write()

I'm new to nodejs and marklogic, and I'm following a tutorial for a simple app, I have setup and configured my marklogin login credentials,
when I run this sample code by running node sample.js
the output is write document list cannot process response with 404 status
I wonder why I'm encountering this error,
here is the code from the tutorial,
my-connection.js
module.exports = {
connInfo: {
host: '127.0.0.1',
port: 8001,
user: 'user',
password: 'password'
}
};
sample.js
const marklogic = require('marklogic');
const my = require('./my-connection.js');
const db = marklogic.createDatabaseClient(my.connInfo);
const documents = [
{ uri: '/gs/aardvark.json',
content: {
name: 'aardvark',
kind: 'mammal',
desc: 'The aardvark is a medium-sized burrowing, nocturnal mammal.'
}
},
{ uri: '/gs/bluebird.json',
content: {
name: 'bluebird',
kind: 'bird',
desc: 'The bluebird is a medium-sized, mostly insectivorous bird.'
}
},
{ uri: '/gs/cobra.json',
content: {
name: 'cobra',
kind: 'mammal',
desc: 'The cobra is a venomous, hooded snake of the family Elapidae.'
}
},
];
db.documents.write(documents).result(
function(response) {
console.log('Loaded the following documents:');
response.documents.forEach( function(document) {
console.log(' ' + document.uri);
});
},
function(error) {
console.log('error here');
console.log(JSON.stringify(error, null, 2));
}
);
I hope someone can tell me what is wrong with the code,
Thank You!
The MarkLogic NodeJS Client library is meant to run against a so-called MarkLogic REST-api instance. There is typically one running at port 8000, but you can also deploy other ones at different ports by issuing a POST call to :8002/v1/rest-apis, as described here:
http://docs.marklogic.com/REST/POST/v1/rest-apis
Port 8001 however is reserved for the MarkLogic Admin UI, which doesn't understand the REST calls that the NodeJS Client library is trying to invoke, hence the 404 (not found)..
HTH!

adCreative create Error: 'Invalid parameter' code: 1487390

Cannot create adCreative. Get an error:
Adcreative Create Failed: The Adcreative Create Failed for the following reason: Oops, something went wrong. Please try again later
and in the same error stack:
message: 'Invalid parameter'
code: 1487390
My code:
exports.create = (data, campaign) => {
return new adsSdk.AdCreative({
body: data.appearance.vacancyDescription,
image_url: data.appearance.backgroundImage,
name: `Creative for campaign ${campaign.id}`,
link_url: data.appearance.link,
title: data.appearance.linkDescription,
object_story_spec: {
instagram_actor_id: 'xxxxxx',
page_id: 'xxxxx',
link_data: {
link: data.appearance.link
}
}
}, `act_xxxxx`)
.create()
I'm using facebook-js-ads-sdk.
The problem was because of wrong page_id

Resources