Mutable Value in Firebase Push Notification Node.js 10 correct syntax? - node.js

I am trying to add Mutable_Content to my push notifications so I can add a badge count.
However I am running into the error:
Messaging payload contains an invalid value for the "notification.mutable_content" property. Values must be strings.
Here is my code for the payload:
const payload = {
notification : {
title: owner + ' has made a post',
body: title + ' - ' + caption,
mutable_content : true
},
};
I have tried many different tutorials to figure out the right syntax but it is not working.
It always comes up with an error.
I am using node.js 10 for the engine and firebase/google cloud platform to trigger the function.
Can anyone help me with this syntax?
Thank you

I had the same question and found unrelated and outdated firebase documentation about it. But you can bypass this by adding a apns field where you can directly put data for the apple notification service. But beware to use the apple syntax with hyphen.
See also: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification
var message = {
notification: {
title: "my notification title",
body: "hello"
},
apns: {
payload: {
aps: {
'mutable-content': true
}
}
},

Related

(NodeJS) WordPress API, updating Events Calendar event (tribe event) removes featured image from post

I'm using the Wordpress API to update tribe events. The updates are successfully sent (and the change is made) but as a side-effect, any time I do it, the featured image is removed from the post...
wpapi package setup:
Because The Events Calendar has it's own routes that aren't built-in by default in the wpapi package, I use the wp.registerRoute function to set that up. I don't think there's a problem with the way I set that up because otherwise it works.
var WPAPI = require( 'wpapi' );
var wp = new WPAPI({
endpoint: 'https://www.example.com/wp-json',
username: 'username',
password: 'mypassword'
});
wp.tribeevent = wp.registerRoute('tribe/events/v1', '/events/(?P<id>)');
example update:
function showEvent (post_id) {
let data = { "hide_from_listings" : false }
wp.tribeevent().id(post_id).update(data)
}
Haven't been able to find anyone with this issue online, so I'm posting here after exhausting myself trying to get it to work without removing the image... Am I doing this wrong? Is this just a bug? Any suggested workarounds?
I've also tried adding the existing image info into the update data sent, but I get this response when doing so:
{
"error": {
"code": "rest_invalid_param",
"message": "Invalid parameter(s): image",
"data": {
"status": 400,
"params": {
"image": "Invalid parameter."
},
"details": []
}
}
}
Otherwise, when making an update such as { "hide_from_listings" : false }, when the json response comes back, the value of the image key just comes back as false: { "image" : false }
Would greatly appreciate any kind of input on this issue...

Firebase cloud messaging android priority property

I am attempting to set a notification priority to HIGH, as noted in the docs here and specific parameter defined here. However, when I set this property in my cloud function, I get the following error when attempting to deploy:
src/index.ts:107:35 - error TS2345: Argument of type '{ tokens: string[]; notification: { title: string; body: any; }; data: { title: any; subtitle: any; body: any; id: any; }; android: { notification: { icon: string; channel_id: string; tag: any; }; priority: string; }; }' is not assignable to parameter of type 'MulticastMessage'.
The types of 'android.priority' are incompatible between these types.
Type 'string' is not assignable to type '"normal" | "high" | undefined'.
107 admin.messaging().sendMulticast(message)
~~~~~~~
I understand this means I shouldn't be entering a string. But according to the docs, that's the expected type. Not only that, but I'm very confused on what type it's referring to in the quotations marks '"normal | "high" | undefined'. What is that type?
Here is the full message container being set:
const message = {
tokens: tokens,
notification: {
title: snapshot.data().sender_username + " - " + snapshot.data().group_name,
body: snapshot.data().content
},
data: {
title: snapshot.data().group_name,
subtitle: snapshot.data().sender_username,
body: snapshot.data().content,
id: message_topic
},
android: {
notification: {
icon: 'add_circle_outline',
channel_id: 'exampleChannelId',
tag: message_topic
},
priority: "high" // <-- This is where the error is thrown
}
};
The IDE is unhappy due to a perceived type mismatch.
A solution is to explicitly type the android config:
import * as admin from 'firebase-admin';
const androidConfig: admin.messaging.AndroidConfig = {
priority: 'high',
...,
};
const message = {
...,
android: androidConfig,
};
This is nice cause you get to see what other config options you can set. On that note you can also explicitly type your entire message, in this case that would be admin.messaging.MulticastMessage
It seems that you need to set the priority in other locations, for it to be set correctly and no error be thrown. If you check this documentation here, it seems that it would need to be written in a different format.
I did further investigation and I could find these two below posts on the Community, that might help you achieve your goal of setting the priority to high.
set FCM high-priority when using firebase-admin
How I can specify the priority on FCM message?
This other article - Working easily with FCM push notifications in Android - might provide some additional ideas on how to achieve that.
Let me know if the information helped you!

Add two more keys and values to a requested array of objects with the same values?

I'm using Node.js to make a Axios request to the Vimeo API.
I'm kind of a Noob with Json but I'd like to understand. I made a call to Vimeo with a filter of name, so I get an "array of objects" (I hope that name is correct ) it looks like this below:
[{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' } ] }
This is simply the names of the videos, however I need to add two keys value pairs with the same value as the name value for a dropdown menu, so it looks like this below:
[{ name: 'A Personalized Goal for Anthony',
"text": "A Personalized Goal for Anthony",
"value": "A Personalized Goal for Anthony" },
{ name: 'Flow access & overview',
"text": "Flow access & overview"
"value": "Flow access & overview" },
{ name: 'Welcome - 2018 Conference',
"text": "Welcome - 2018 Conference"
"value": "Welcome - 2018 Conference" },
{ name: 'Dropout Video',
"text": "Welcome - 2018 Conference"
"value": "Welcome - 2018 Conference" }]
My app needs the keys "Text" and "Value" for a dropdown menu in order to process the response from the user.
I'm not sure why { name: 'Dropout Video'}, isn't formatted like this {"name":"Dropout Video"},
Is there a way in Node.js to add or duplicate an array using map or push using the same name value while also doing a foreach to this array which reflects the name but with two additional key value pairs with the same Value as the key Name?
This is a dynamic Object as well so when the request is called again it could have many more than just 4 video names returned.
My goal is to add numerous Videos to a Vimeo Album that I want to make the request to, then my app ( Slack chatbot ) then returns a list of options via a drop down menu for the users consideration so that I'm able to see which Name or title they selected and thus want more information on.
Thank you so much any help here. I wish Vimeo had a Text and Value field so I could just filter that instead but then it wouldn't be fun :)
You could map through your result, so, for example, after you get the result:
const movies = [{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' }];
You could map it to add the other two properties to each one of your objects, the advantage is that you are not mutating your results.
const mappedMovies = movies.map(movie => {
return {
name: movie.name,
text: movie.name,
value: movie.name
}
);
In that way, you will have the list of objects with the format that you want, now if you need it in json format you could do:
const JSONString = JSON.stringify(mappedMovies);
Objects are references, so you could just loop through your objects and add the keys.
const videos = [
{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' }
]
for (video of videos) {
video.text = video.name
video.value = video.name
}
console.log(videos)
Welcome to SO Kevin,
It looks like you almost provided the answer yourself already...
To get the resulting array you can map through the object and add keys as required:
const slackVideos = videos.map(function (item, label) {
return {
...item, //this ensures all original keys are available, using the ES6 destructuring
text: item.name,
value: item.value,
}
});
Assuming videos is the object received from vimeo, slackVideos will now contain your aditional text & value keys; both containing the name key from the original vimeo object.

How to do Autocomplete text suggestion in message box in BOT

I created a BOT with LUIS and node.js and also published in Skype Channel.
Now I wants to add Autocomplete text suggestion in message box.
Am unable to find documentation for node.js
Please assist me.
Autcomplete can be accomplished with a few different NPM packages. Here's one as an example that looks not too bad to implement: https://www.npmjs.com/package/autocompleter
Code example:
var countries = [
{ label: 'United Kingdom', value: 'UK' },
{ label: 'United States', value: 'US' }
];
autocomplete({
input: document.getElementById("country"),
fetch: function(text, update) {
text = text.toLowerCase();
// you can also use AJAX requests instead of preloaded data
var suggestions = countries.filter(n => n.label.toLowerCase().startsWith(text))
update(suggestions);
},
onSelect: function(item) {
alert(item.value); // will display 'US' or 'UK'
}
});
You'll obviously have to adapt this to your needs and exact use case, but should be easy enough to implement.

Container Builder Slack Notifications

we're testing out CB and part of our requirements is sending messages to Slack.
This tutorial works great, but it'd be helpful if we could specify the source of the build, so we don't have to click in to the message to see what repo/trigger failed/succeeded.
Is there a variable we can pass to the cloud function in the tutorial? I couldn't find helpful documentation.
Ideally, it would be great if CB had an integration/slack GUI that made these options configurable but c'est la vie.
You can add source information to the slack message by adding a new item to the fields list within the createSlackMessage function. You need to make sure title and value are strings.
// createSlackMessage create a message from a build object.
const createSlackMessage = (build) => {
let message = {
text: `Build \`${build.id}\``,
mrkdwn: true,
attachments: [
{
title: 'Build logs',
title_link: build.logUrl,
fields: [{
title: 'Status',
value: build.status
},{
title: 'Source',
value: JSON.stringify(build.source, null, 2)
}]
}
]
};
return message
}
You can find more information on build object here.

Resources