The code is working fine when I try to send notification on android but it does not work for IOS notification. Getting the below error:
{
"results": [
{
"error": {
"code": "messaging/internal-error",
"message": "An internal error has occurred. Please retry the request."
}
}
],
"canonicalRegistrationTokenCount": 0,
"failureCount": 1,
"successCount": 0,
"multicastId": 8118740071861272000
}
This is my code sample, please take a look and help me to resolve the issue.
also, I get a notification when I try to send notification from cloud messages console.
return await admin.messaging()
.sendToDevice(deviceToken, {
data: {
title: 'Test Fcm',
body: 'tesing fmc body',
content_available: 'true',
priority: 'high',
action_type: 'TEST'
},
notification: {
title: 'Test Fcm',
body: 'tesing fmc body',
content_available: 'true',
priority: 'high'
}
}
, {
priority: "high",
timeToLive: 60 * 60 * 24,
contentAvailable:true,
}).catch(err => {
console.log(err);
})
i have encount 2 days ago this issue.
just remove 'content_available' from 'notification', it's working.
example for your json =>
{
data: {
title: 'Test Fcm',
body: 'tesing fmc body',
content_available: 'true',
priority: 'high',
action_type: 'TEST'
},
notification: {
title: 'Test Fcm',
body: 'tesing fmc body',
=> content_available: 'true', // remove this
priority: 'high'
}
}
regards.
Related
When I run the script for my discord bot and use /warn remove it keeps throwing an error that user is of type string expected USER. It says the error is happening between lines 69:42 and I can't find the issue.
module.exports = {
category: 'Moderation',
description: 'Warn a user',
permissions: ['ADMINISTRATOR'],
slash: true,
guildOnly: true,
options: [
{
type: 'SUB_COMMAND',
name: 'remove',
description: 'Removes a warning from the user',
options: [
{
name: 'user',
type: 'USER',
description: 'The user to remove the warning from',
required: true,
},
{
name: 'id',
type: 'STRING',
description: 'The ID of the warning to remove',
required: true,
},
],
}
],
callback: async ({ guild, member: staff, interaction }) => {
const user = interaction.options.getUser('user')
if (subCommand === 'remove') {
const warning = await warnSchema.findByIdAndDelete(id)
return {
custom: true,
content: `Removed warning ${warning.id} from <#${user?.id}>`,
allowedMentions: {
users: []
}
}
}
}
}
I didn't post all the code because it seemed like it would be too much searching but this is the code that is causing the error.
I am trying to make a toggle able slash command, if they pick the disable option it turns it off but when if you pick the enable option it asks to pick a channel but it gives this error
Error:
DiscordAPIError[50035]: Invalid Form Body
23.name[BASE_TYPE_REQUIRED]: This field is required
rawError: {
code: 50035,
errors: { '23': [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'put',
url: 'https://discord.com/api/v9/applications/971024098098569327/commands'
Code:
module.exports = {
name: 'welcomer',
permissions: 'MANAGE_CHANNELS',
description: 'Set Where Welcome Messages Get Sent To.',
options: [
{
name: 'toggle',
description: 'Toggle On/Off The Welcomer',
type: 3,
required: true,
choices: [
{
name: 'disable',
value: 'off',
},
{
name: 'enable',
value: 'on',
choices: [
{
name: 'channel',
description: 'Select channel to send welcome messages to',
type: 7,
required: true,
},
]
},
],
},
],
Those would be an example of a subcommand and need to be indicated as such and will need descriptions in a couple places.
module.exports = {
name: 'welcomer',
permissions: 'MANAGE_CHANNELS',
description: 'Set Where Welcome Messages Get Sent To.',
options: [{
name: 'disable',
description: `'Disable welcomer`, // Added needed description
type: 1, //converted to subcommmand
}, {
name: 'enable',
description: `'Enable welcomer`, // Added needed description
type: 1, //converted to subcommmand
options: [{
name: 'channel',
description: 'Select channel to send welcome messages to',
type: 7,
required: true,
channel_types: [0] // allows only text channels to be selected
}]
}],
// run command pick only one of the below two
// if command.execute()
async execute(client, interaction, args)
// if command.run()
run: async (client, interaction, args) =>
// command code below here assumes you have the code in your `interactionCreate` listener to set up args
{
if (args.disable) {
// Code to turn off
} else if (args.enable) {
const channel = args.channel
// Code to turn on
};
}
}
I am trying to get a custom sound in android when receiving a notification when the app is in the background.
Here is my code I have tried but is not working. What am I doing wrong???
const message: admin.messaging.Message = {
data: {
type: "message",
Id: Id
},
notification: {
body: "Body",
title: "title"
},
android: {
ttl: 60000,
priority: "high",
notification: {
body: "Android test body",
title: "Android test title",
sound: "test.wav"
}
},
apns: {
headers: {
"apns-priority": "10",
"apns-expiration": "" + (Math.floor(Date.now() / 1000) + 60)
},
payload: {
aps: {
sound: "OnceAgainNotification.caf"
}
}
},
token: token
};
I am trying to implement paypal subscription api in react-nodejs project.i refer https://developer.paypal.com/docs/api/subscriptions/v1/. after that i got id wit "P-*********".
What i have tried is:
in Ui Side(React) i created an event for requesting server side to create the billing plans.
in server side(nodejs) i do billingPlan create and update actions.
The code is:(nodejs)
export const paypalSubscribe = async (user, data) => {
const customerId = user.customer,
{ invoice: invoiceId } = data;
try {
const billingPlanAttributes = {
description: "Create Plan for Regular",
merchant_preferences: {
auto_bill_amount: "yes",
cancel_url: "http://www.cancel.com",
initial_fail_amount_action: "continue",
max_fail_attempts: "1",
return_url: "http://www.success.com",
setup_fee: {
currency: "USD",
value: "25"
}
},
name: "Testing1-Regular1",
payment_definitions: [
{
amount: {
currency: "USD",
value: order.price.recurringAmount
},
charge_models: [
{
amount: {
currency: "USD",
value: "10.60"
},
type: "SHIPPING"
},
{
amount: {
currency: "USD",
value: "20"
},
type: "TAX"
}
],
cycles: "0",
frequency: "MONTH",
frequency_interval: order.billingCycle,
name: "Regular 1",
type: "REGULAR"
}
],
type: "INFINITE"
};
const createdBillingPlan = await new Promise((resolve, reject) => {
Paypal.billingPlan.create(billingPlanAttributes, function (
error,
billingPlan
) {
if (error) {
reject(error);
} else {
resolve(billingPlan);
}
});
});
console.log("data123....", createdBillingPlan);
// update
var billing_plan_update_attributes = [
{
op: "replace",
path: "/",
value: {
state: "ACTIVE"
}
}
];
console.log(
"billing_plan_update_attributes",
billing_plan_update_attributes
);
const updateBillingPlan = await new Promise((resolve, reject) => {
Paypal.billingPlan.update(
createdBillingPlan.id,
billing_plan_update_attributes,
function (error, response) {
if (error) {
reject(error);
} else {
resolve(response);
}
}
);
});
const getBillingPlan = await new Promise((resolve, reject) => {
Paypal.billingPlan.get(createdBillingPlan.id, function (
error,
updatedBillingPlan
) {
if (error) {
console.log("errr", error.response);
reject(error);
} else {
console.log("updatedBillingPlan", JSON.stringify(updatedBillingPlan));
resolve(updatedBillingPlan);
updatedBillingPlan.redire
}
});
});
console.log("getBillingPlan", getBillingPlan);
return { ok: true, data: getBillingPlan };
} catch (error) {
console.log("error", error);
}
};
And i got getBillingPlan is like this:
{ id: 'P-**************',
state: 'ACTIVE',
name: 'Testing1-Regular1',
description: 'Create Plan for Regular',
type: 'INFINITE',
payment_definitions:
[ { id: 'PD-0EF41434TA3045459BCMIRMA',
name: 'Regular 1',
type: 'REGULAR',
frequency: 'Month',
amount: [Object],
cycles: '0',
charge_models: [Array],
frequency_interval: '1' } ],
merchant_preferences:
{ setup_fee: { currency: 'USD', value: '25' },
max_fail_attempts: '1',
return_url: 'http://www.success.com',
cancel_url: 'http://www.cancel.com',
auto_bill_amount: 'YES',
initial_fail_amount_action: 'CONTINUE' },
create_time: '2020-07-01T04:18:01.008Z',
update_time: '2020-07-01T04:18:02.031Z',
links:
[ { href:
'https://api.sandbox.paypal.com/v1/payments/billing-plans/P-***********',
rel: 'self',
method: 'GET' } ],
httpStatusCode: 200
}
And when i trying to open the links in links array
ie,https://api.sandbox.paypal.com/v1/payments/billing-plans/P-***********' i got the error:
"Authentication failed due to invalid authentication credentials or a missing Authorization
header."
Where i went wrong? How can i resolve this and implement subscription of paypal in my Project.
REST Api
i changed my code to rest api calls finaly i got response like this:
{ status: 'APPROVAL_PENDING',
id: 'I-1FU83BNMBCFS',
create_time: '2020-07-06T09:47:02Z',
links:
[ { href:
'https://www.sandbox.paypal.com/webapps/billing/subscriptions? ba_token=BA-3D945638N1691194P',
rel: 'approve',
method: 'GET' },
{ href:
'https://api.sandbox.paypal.com/v1/billing/subscriptions/I- 1FU83BNMBCFS',
rel: 'edit',
method: 'PATCH' },
{ href:
'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-1FU83BNMBCFS',
rel: 'self',
method: 'GET' } ],
responseCode: 201 }
and in my ui side i opened the approval link in new window after submitting it shows 404. Why?
code:
window.open(URL, "_blank");
UPDATE:Subscription:
const subscriptionString = {
plan_id: result.id,
start_time: "2021-11-01T00:00:00Z",
shipping_amount: {
currency_code: "USD",
value: "10.00"
},
subscriber: {
name: {
given_name: "John",
surname: "Doe"
},
email_address: "customer#example.com",
shipping_address: {
name: {
full_name: "John Doe"
},
address: {
address_line_1: "2211 N First Street",
address_line_2: "Building 17",
admin_area_2: "San Jose",
admin_area_1: "CA",
postal_code: "95131",
country_code: "US"
}
}
},
application_context: {
brand_name: "walmart",
locale: "en-US",
shipping_preference: "SET_PROVIDED_ADDRESS",
user_action: "SUBSCRIBE_NOW",
payment_method: {
payer_selected: "PAYPAL",
payee_preferred: "IMMEDIATE_PAYMENT_REQUIRED"
},
return_url: "https://example.com/returnUrl",
cancel_url: "https://example.com/cancelUrl"
}
},
options = {
url: "https://api.sandbox.paypal.com/v1/billing/subscriptions",
method: "POST",
headers: headers,
body: JSON.stringify(subscriptionString)
},
activateResult = await payment.callPayaplApi(options);
return {
ok: true,
data: activateResult
};
}
There is no SDK for a Subscriptions API integration, you need to implement direct REST API calls.
The PayPal-Node-SDK never supported the Subscriptions API, only the previous billing APIs which are not compatible. Also, the PayPal-Node-SDK is no longer maintained.
You particular authentication error is due to something else, but due to the above issues it is not worth troubleshooting.
Start over and integrate correctly with direct REST API calls.
It seems to be a simple parameter I'm missing but I'm having trouble figuring out exactly what it is.
This is the request I'm sending with '#sendgrid/mail':
email.js:
const sgMail = require('#sendgrid/mail');
function emailRequest() {
msg = {
to: 'test+10#gmail.com
from: 'info#owner.io',
subject: 'Receipt for Business Expenses',
template_id: 'db6d11ae-41e4-4e1a-a71b-f5368eb21c9c',
personalizations: [
{
to: 'test+10#gmail.com,
from: 'info#ownr.io,
subject: 'Receipt for Business Expenses,
template_id: 'db6d11ae-41e4-4e1a-a71b-f5368eb21c9c',
substitutions: {
':firstname': 'Bobba',
':ordernumber': 'WHAAA',
':orderdate': 'today',
':ordertime': 'NOW!',
},
custom_args: {
':firstname': 'Bobba',
':ordernumber': 'WHAAA',
':orderdate': 'today',
':ordertime': 'NOW!',
},
},
],
sub: {
':firstname': 'Bobba',
':ordernumber': 'WHAAA',
':orderdate': 'today',
':ordertime': 'NOW!',
},
substitutions: {
':firstname': 'Bobba',
':ordernumber': 'WHAAA',
':orderdate': 'today',
':ordertime': 'NOW!',
},
};
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
return sgMail
.send(msg)
.then(response => {
return response;
})
.catch(err => {
throw err;
});
}
The email sends, but I'm still getting unsubstituted templates:
The source code for sendgrid-nodejs mail.js seems to say that as long as there is 'substitutions', it will initialize the mailing class with those substitutions but it's not working:
https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/mail.js
https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
How do you properly substitute variables into templates? Am I using the wrong package?
After a bit more digging, I found the answer in the issues section of their github. I was missing 'substitutionWrappers'. To get it working, all I had to do was add 'substitutionWrappers' to the message along with 'substitutions':
const msg = {
to: 'test#email.com'
from: 'info#gmail.io',
subject: 'Receipt for Business Expenses',
template_id: 'da6db3ae-41e4-4e1a-a71b-f5368ab41c9c',
substitutionWrappers: [':', ''],
substitutions: {
firstname: 'Bobba',
ordernumber: 'WHAAA',
orderdate: 'today',
ordertime: 'NOW!',
},
};
There's no need to specify the substitution wrappers as it will assume that you're using Handlebars templating by default.
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'recipient#example.org',
from: 'sender#example.org',
templateId: 'd-f43daeeaef504760851f727007e0b5d0',
dynamicTemplateData: {
subject: 'Testing Templates',
name: 'Some One',
city: 'Denver',
},
};
sgMail.send(msg);
Check documentation to learn more