Unsubscribe from channel via REST API in Parse - push-notification

Does anyone know how to unsubscribe from a channel or all channels in parse via REST API? The documentation say you have to update the channels array, but is not working for me or i'm doing something wrong.
Thanks

There's a section of the documentation that shows adding a channel:
https://parse.com/docs/rest#installations-updating
You would need to put the whole contents of the Installation including existing channels, plus the new one.
Alternatively you can make atomic changes to just the channels array as described in this section of the docs under the "Arrays" heading:
https://parse.com/docs/rest#objects-updating
As shown there you can use Add, AddUnique and Remove. To add a single channel you're best using AddUnique.
So, to answer your question, you can use the Remove for a single channel or a couple of channels using the following parameters:
{"channels":{"__op":"Remove","objects":["channel 1","channel 2"]}}
To remove all channels you would perform an update with channels set to the default, e.g:
{
"deviceType": "ios",
"deviceToken": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"channels": [
""
]
}

Related

Exclude nextjs api url from sentry events

I have nextjs app with sentry. I want to add new api route, for example api/status, but I want to exclude it from being sent to sentry as it will clutter logs really fast and use my qouta.
I did a small research and it seems that there is an array of urls you can exclude from being tracked. It's called denyUrls. Read more. I have tried to add my url to this array, but it still tracks this url as part of events:
Sentry.init({
...
denyUrls: [
/api\/status/i,
],
...
});
Am I configuring something wrong or this array is not for the purpose of filtering everts.
If so, what's the best way to filter those? Other option I found which I will try next is beforeSend but it feels a bit overkill to simply exclude url. denyUrls feels like much better fit for what I am trying to achieve
I had the same issue and contacted the support for it. I am directly quoting the support here.
The BeforeSend and DenyUrl are options to filter error events, not transactions. For transaction events, please use the tracesSampler function as described on the page: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/sampling/#setting-a-sampling-function.
Here is an example to drop all transactions that match a certain name:
tracesSampler: samplingContext => {
if(samplingContext.transactionContext.name == "GET /api/health"){
return 0.0 // never send transactions with name GET /api/health
}
return 0.2 // sampling for all other transactions
}
Note that you might need to customise the function above to better match your scenario.
I hope it will help you ;)
Have a nice day.

How to store keywords in firebase firestore

My application use keywords extensively, everything is tagged with keywords, so whenever use wants to search data or add data I have to show keywords in auto complete box.
As of now I am storing keywords in another collection as below
export interface IKeyword {
Id:string;
Name:string;
CreatedBy:IUserMin;
CreatedOn:firestore.Timestamp;
}
export interface IUserMin {
UserId:string;
DisplayName:string;
}
export interface IKeywordMin {
Id:string;
Name:string;
}
My main document holds array of Keywords
export interface MainDocument{
Field1:string;
Field2:string;
........
other fields
........
Keywords:IKeywordMin[];
}
But problem is auto complete reads data frequently and my document reads quota increases very fast.
Is there a way to implement this without increasing reads for keyword ? Because keyword is not the real data we need to get.
Below is my query to get main documents
query = query.where("Keywords", "array-contains-any", keywords)
I use below query to get keywords in auto complete text box
query = query.orderBy("Name").startAt(searchTerm).endAt(searchTerm+ '\uf8ff').limit(20)
this query run many times when user types auto complete search which is causing more document reads
Does this answer your question
https://fireship.io/lessons/typeahead-autocomplete-with-firestore/
Though the receommended solution is to use 3rd party tool
https://firebase.google.com/docs/firestore/solutions/search
To reduce documents read:
A solution that come to my mind however I'm not sure if it's suitable for your use case is using Firestore caching feature. By default, firestore client will always try to reach the server to get the new changes on your documents and if it cannot reach the server, it will reach to the cached data on the client device. you can take advantage of this feature by using the cache first and reach the server only when you want. For web application, this feature is disabled by default and you can enable it like in
https://firebase.google.com/docs/firestore/manage-data/enable-offline
to help you understand this feature more check this article:
https://firebase.google.com/docs/firestore/manage-data/enable-offline
I found a solution, thought I would share here
Create a new collection named typeaheads in below format
export interface ITypeAHead {
Prefix:string;
CollectionName:string;
FieldName:string;
MatchingValues:ILookupItem[]
}
export interface ILookupItem {
Key:string;
Value:string;
}
depending on the minimum letters add either 2 or 3 letters to Prefix, and search based on the prefix, collection and field. so most probably you will end up with 2 or 3 document reads for on search.
Hope this helps someone else.

How to hide Telegram BOT commands when it is part of a group?

I'm trying to use a Telegram BOT to send messages to a group. First, I thought that it'd be enough to know the group chat id to accomplish that, but it's not. The BOT MUST be part of that group. OK, it kind of make sense, but the problem is: When you add a BOT into a group (a large group in this case) everyone start seeing a new icon on their devices, a "slash" icon. And what do they do ? They click on it, see the list of commands, choose one of them, and all of a sudden everyone is getting a new message from the group: a "/something". Imagine dozens of people doing that ? It's pretty annoying. So, any of these would work for me:
1) Can I send messages from a BOT to a group without having that BOT in the group ?
2) Can I have a kind of "no methods" BOT, that only send messages ?
3) Can I disable "slash" icon from clients so I won't have a "bot method war" in the group ?
Thank you
No, you cannot have bots send messages to a group without being a part of that group.
You can simply not set commands with BotFather, and then clients will have no commands to display.
It is always there if a bot is in the current chat, but here is what it does with no commands set in BotFather:
I got a much better solution: there is the possibility to customize the commands directly by code, also depending from the context (i.e. private chat, groups, etc...)
This example was done by using Telegraf but that's not so different from basic code
bot.start(function(ctx) {
// If bot is used outside a group
ctx.telegram.setMyCommands(
[
{
"command": "mycommand",
"description": "Do something in private messages"
}, {
"command": "help",
"description": "Help me! :)"
}
],
{scope: {type: 'default'}}
)
// If bot is used inside a group
ctx.telegram.setMyCommands(
[
// <-- empty commands list
],
{scope: {type: 'all_group_chats'}}
)
ctx.reply('Hello! I\'m your super-cool bot!!!')
})
Bonus Point, you can also manage the command behavior by checking the source.
So, for example, if a user in a group still try to use manually your command and you don't want to execute anything:
bot.help(function(ctx) {
// Check if /help command is not triggered by a private chat (like a group or a supergroup) and do nothing in that case
if (ctx.update.message.chat.type !== 'private') {
return false
}
ctx.reply('Hi! This is a help message and glad you are not writing from a group!')
})

Meteor: Single-Document Subscription

Whenever I encounter code snippets on the web, I see something like
Meteor.subscribe('posts', 'bob-smith');
The client can then display all posts of "bob-smith".
The subscription returns several documents.
What I need, in contrast, is a single-document subscription in order to show an article's body field. I would like to filter by (article) id:
Meteor.subscribe('articles', articleId);
But I got suspicious when I searched the web for similar examples: I cannot find even one single-document subscription example.
What is the reason for that? Why does nobody use single-document subscriptions?
Oh but people do!
This is not against any best practice that I know of.
For example, here is a code sample from the github repository of Telescope where you can see a publication for retrieving a single user based on his or her id.
Here is another one for retrieving a single post, and here is the subscription for it.
It is actually sane to subscribe only to the data that you need at a given moment in your app. If you are writing a single post page, you should make a single post publication/subscription for it, such as:
Meteor.publish('singleArticle', function (articleId) {
return Articles.find({_id: articleId});
});
// Then, from an iron-router route for example:
Meteor.subscribe('singleArticle', this.params.articleId);
A common pattern that uses a single document subscription is a parameterized route, ex: /posts/:_id - you'll see these in many iron:router answers here.

Firebase REST API Query Parameters?

Is it possible to filter data returned by the Firebase REST API using query parameters? I don't see it mentioned one way or an other in the docs, but the client libraries support it, so I'm hoping it's possible. Thanks.
It might be a bit late to answer, but Firebase does allow querying data via REST.
You can use the orderby option together with limitToLast, startAt etc just like you would when using the SDK.
Checkout the Firebase guide for more details
I fought a little bit to have it working.
I actually needed 2 things:
combine limitToLast with orderBy as mentioned by idan
URL getUrl = new URL( url + "news.json?orderBy=\"timestamp\"&limitToLast=5" );
add a rule in the database to declare an index on this "column"
"news" : { ".indexOn": "timestamp" }
Firebase provides querying parameters. However, I don't think they are the querying parameters you are expecting them to be, which are ones that filter data. Firebase REST API provides querying options like auth, print, callback, format, and download. Check docs here
Without ordering by certain field, By combining params orderBy="$key" and limitToLast=5 you can get the last 5 of inserted data ordered by it's key
The documentation can be looked at here

Resources