Parse Push Notification Remove Scheduled Push - javascript

I have scheduled a parse push notification using cloud code. Now is there a way
change the date/time of that notification.
remove this notification from schedule.
var query = new Parse.Query(Parse.Installation);
query.equalTo('group_id', 'xxx');
Parse.Push.send({
where: query,
data: {
alert: "You previously created a reminder for the game today"
},
push_time: new Date(2014, 12, 30)
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});

There currently is NO API methods for this. I will update my answer when any major updates to their SDK have been published.
A work around is schedule a local push notification within Apples/Googles allowance and alter it thereafter when necessary.
Conversely,
Another way you could do it but will be code heavy; but create a push notification class on Parse Backend. Have pointers to users and create a few columns, one specifically will be a Parse Date with the proposed notification time. Update when necessary through the users device actions that way your not locked down to the one notification method set in stone. Everything is handled via cloud.

Related

odoo notification if the record data is out of date

when odoo 15 was released I have seen this record is not up to date (not sure of the actual words)
The issue is that I have a approval for a record but if the user that summered the record for approval is still on the page he don't see the updates to the record after the approval. I do send the notification but the user wants the page to refresh or show that the record view is not up to date like (what odoo was doing in the first week of the released)
sorry is there is no code but am not sure how go about doing this.
Not expecting a solution just ideas on what you thing and maybe in you have time why your idea may fail (drawbacks).
/**
* Displays one notification on user's screen when assets have changed
*/
function displayBundleChangedNotification() {
if (!isNotificationDisplayed) {
// Wrap the notification inside a delay.
// The server may be overwhelmed with recomputing assets
// We wait until things settle down
browser.clearTimeout(bundleNotifTimerID);
bundleNotifTimerID = browser.setTimeout(() => {
notification.add(
env._t("The page appears to be out of date."),
{
title: env._t("Refresh"),
type: "warning",
sticky: true,
buttons: [
{
name: env._t("Refresh"),
primary: true,
onClick: () => {
browser.location.reload();
},
},
],
onClose: () => {
isNotificationDisplayed = false;
},
}
);
isNotificationDisplayed = true;
}, getBundleNotificationDelay());
}
}
addons/bus/static/src/js/services/assets_watchdog_service.js
this maybe semlar to what I need but assets
The main question here Is how to know if a user is on the modified record and run a function
setup a web socket that listens for update events identified
by ID’s and prompt notifications if the documentId of the
notification matches the ID of document on page at that point in
time.
Poll every x seconds for the record corresponding to document on page and compare some unique value that would have changed like lastUpdated. If changed prompt notification and refresh.
Keep a metadata list of open pages. Can use heartbeat interval and onLoad onUnload events to keep list valid. Whenever two or more documents are open at the same time make it known on page that “document is being edited and cannot be currently edited will update accordingly” or something like that.
Use service workers and the push api to send updates to the main running app

Updating an activity in BotFramework v4 on Teams platform

I have a bot developed using the Bot Framework v4 using NodeJS and deployed on multiple channels in Teams. Is there a way we can update a message sent by the bot? I tried implementing the updateActivity() function in the BotFrameworkAdapter. However, it does not update the activity.
I have this card sent from the bot to a Teams channel. When someone clicks on the button, is there a way I can update the card or the message (disabling the button)?
The key to this is making sure that when you use updateActivity(), you use the right activity ID that is created by the Teams Channel. You also need to make sure that the updated activity gets all of the Teams data set to it.
In onTurn, capture outgoing activities so that you can easily save all of the necessary Teams Channel data:
public onTurn = async (turnContext: TurnContext) => {
turnContext.onSendActivities(async (ctx, activities, nextSend) => {
activities.forEach(async (activity) => {
if (activity.channelData.saveMe) {
this.savedActivity = activity;
}
});
return await nextSend();
});
Note: There might be another way to do this. I just found this to be the easiest, since you need to save all of the channelData, conversation info, and activity.id, at a minimum
How you store that activity to be used later is up to you. If you store it in the constructor, it will either be re-instantiated on every message (C# SDK) or any user has the ability to change it (JS SDK). You might consider writing custom storage.
Activities keep all channelData. By specifying a saveMe flag, we ensure we save the right activity
Instantiate some key variables:
const teamsChannel = '19:8d60061c3d10xxxxxxxxxxxxxxxx#thread.skype';
const serviceUrl = 'https://smba.trafficmanager.net/amer/';
Note: the easiest way to get these variables is to send a message from Teams to the bot while putting a breakpoint on the incoming activity
serviceUrl likely varies by geo region
Send the first activity and store the ID:
// This ensures that your bot can send to Teams
turnContext.activity.conversation.id = teamsChannel;
turnContext.activity.serviceUrl = serviceUrl;
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
// Add the saveMe flag
yourActivity.channelData = { saveMe: true };
const response = await turnContext.sendActivity(yourActivity);
this.activityToUpdateId = response.id;
How you store that ID to be used later is up to you. If you store it in the constructor, it will either be re-instantiated on every message (C# SDK) or any user has the ability to change it (JS SDK). You might consider writing custom storage.
Update your saved activity:
// New data
const card2 = CardFactory.adaptiveCard(adaptiveCard2);
// Set the saved activity.id and new activity data (an adaptiveCard, in this example)
this.savedActivity.id = this.activityToUpdateId;
this.savedActivity.attachments = [card2];
Send the update:
await turnContext.updateActivity(this.savedActivity);
Note: you can update the activity with anything. I swapped out entirely different Adaptive Cards
Before:
After:
I've tried this using the middleware but keep getting: "The bot is not part of the conversation roster". Question: My bot is updating a message that a user wrote, so do I need special permissions?
let ActivityID = context.activity.conversation.id.split("=")[1];
let updatedActivity: Partial<Activity> = {
"id": ActivityID,
"channelId": context.activity.channelId,
"channelData": context.activity.channelData,
"conversation":
{
"name": "",
"id": context.activity.conversation.id,
"isGroup": context.activity.conversation.isGroup,
"conversationType": context.activity.conversation.conversationType,
"tenantId": context.activity.conversation.tenantId
},
"type": "message",
"text": "",
"summary": "",
"attachments": [ attachment ]
} await context.updateActivity(updatedActivity);

Firebase push() method shuffle the list data

Have created a chat application and we use firebase for realtime communication.
Sometimes i noticed that push() method shuffle the list data. We can see in the below image :
If we see in above image i am just trying to communicate with someone i said hello in reply user said hey, again i said i need some help then user said That's what I'm here for. What can I assist you with? in the reply but if we see in the image users reply is appearing first.
It happens intermittently that's why i didn't figure out this problem. So please someone help me out what shall i doing wrong.
var pushMessageToFB = function(){
var chatMsgRef = db.child("chatMessages").child("gr1").child("ch_usr1_usr2");
var message = {
type: "chat",
content: data.messageText,
timestamp: Date.now(),
by: user.id
};
chatMsgRef.push(message, function(err){
if (err){
console.log('error occurred while pushing message to fb : err ' + JSON.stringify(err));
}
});};
var loadChatMessages = function(){
var chatMsgRef = db.child('chatMessages').child("gr1").child("ch_usr1_usr2");
$scope.chatMessages = chatMsgRef.orderByKey().limitToLast(50);
};
Don't use Date for remote data. It will be slightly offset on every machine. Use ServerValue.TIMESTAMP which Firebase will convert to the server's Unix epoch time when the data is written. This ensures consistency of order across clients.
You didn't provide any code for how you're reading or displaying the chat messages, but since you're trying to show them in chronological order I assume your query uses orderBy("timestamp"). If you use ServerValue.TIMESTAMP when you write the message it will be guaranteed to sort in the order that it was written to the database.

After send webhook of parse push notification

Is it possible to setup a web hook for anytime a push notification is sent via Parse?
I want to retrieve the details of the push notification and set a column against any devices the push notification was sent to
No hook that I'm aware of, but you could run all of your pushes through one place in your code (either client or a cloud function), and do whatever post-push work you want to do there. Presuming JS and advanced targeting, it could look like this:
function pushToInstallations(query, data) {
var params = { where: query, data: data};
return Parse.Push.send(params).then(function() {
// this is the interesting part, run the installation query
return query.find();
}).then(function(installations) {
var date = new Date();
// presumes underscore, but a regular for loop works too
_.each(installations, function(installation) {
installation.set("mostRecentPushDate", date);
});
return Parse.Object.saveAll(installations);
});
}
Then, wherever in your code you were building an installation query and calling push, call your new pushing function instead, like this:
var query = new Parse.Query(Parse.Installation);
query.equalTo('someColumn', someValue);
pushToInstallations(query, {alert: "some message"}).then(function(installations) {
// these installations passed back were pushed to and updated
}, function(error) {
// handle error
});

firebase: get records with dates greater than now

I'm using Firebase for an admin panel which has multiple users. Whenever a new question is added, everyone in the panel gets alerted immediately.
It's working fine, but the way i implemented it doesn't feel right. Here's what i'm doing:
dataRef.auth(token, function(error, result) {
if (error) {
console.log("Login Failed!", error);
} else {
var started = new Date();
dataRef.on('child_added', function(snapshot) {
var message = snapshot.val();
var t = message.date.split(/[- :]/);
var lastChildDate = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
if(lastChildDate > started) {
// alert the user
}
});
}
});
And this is the data structure. It only has one field:
{date: "2013-06-14 16:45:10"}
This brings all the records in that base. A child_added event gets fired for all records. I then check if it's created after the page is loaded, and alert the user accordingly. But the clients only need to be alerted for children that are added from now on. How can i get rid of that unnecessary load? I've checked the documentation, but couldn't find an answer.
There's a few ways to solve this issue.
1) Encode the timestamp at which the event occurred in the priority of the new child, and then use "startAt" to prune older elements.
Make sure your encoding of time sorts lexigraphically in time order.
For example:
ref.startAt("2013-06-14 10:11:13").on(...);
When generating the timestamped items, you'll want to use the Firebase server time so everyone is working off of the same clock. See serverTimeOffset:
https://www.firebase.com/docs/managing-presence.html
2) Have a different event queue for every user, and have users' clients remove elements from the queue once they've seen them.
This solution is best in cases where each user might receive different notifications, such as in a social network.

Categories