In Firebase Console I set up audiences based on various user properties and now am able to send notifications to different user segments via console. Is there a way to do the same by http requests to fcm servers? There should be a trick with "to" field, but I couldn't figure it out.
firebaser here
There is currently no way to send a notification to a user segment programmatically. It can only be done from the Firebase Console as you've found.
We're aware that allowing this through an API would expand the potential for Firebase Notifications a lot. So we're considering adding it to the API. But as usual: no commitment and no timelines, since those tend to change as priorities shift.
This has been a popular request, but unfortunately it is not yet possible. We are looking into this.
Please check Firebase Cloud Messaging announcements for any updates in the future.
You can try with topic subscriptions. It is not perfect solution but the best for me at this time.
{
"to": "/topics/audience1_subscription"
"data" : {
"title" : "Sample title",
"body" : "Sample body"
},
}
Yes. No solid solutions are available as of now but I have a workaround solution for it. Which is not able to handle every scenario but it will get the work done.
For that, you need to figure out the audience within the app and you need to segment them with topics. Then you can send a push notification for that particular topic via API.
Let's take an example.
Send notifications to users who didn't open the app in the last 7 days
Subscribe to a topic name "app-open?date=09-21-2022"
each time user opens the app. Just unsubscribe from the topic of the last app opened and subscribe to a new topic with the current date.
Then you just need to build a topic string based on the current day - 7 to send.
And you can create multiple topics for the same user for different behaviors and use them as topics to send push notifications via API to segmented users.
As there is no limit on topics per user or topics per project. You can create as many as topics you want and use them as your need.
Yes.There is trick with the "to" field as mentioned in below.
web URL is: https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key="YOUR_SEVER_KEY"
JSON DATA FORMAT:
{"to": "USER_FIREBASE_TOKEN",
"data": {"message": "This is a Firebase Cloud Messaging Topic Message",}
"notification": {"body": "This is firebase body",}}";
Related
I'm building a web-app that runs analysis on Slack activity and I need test data. Do not know where to turn to, doesn't have to be millions of messages, but need data for the following:
user status (online/away/logged off) changes
messages sent (date, user, contents)
reactions (date, type, reaction on what message)
huddles, voice/video chats with metadata
any help is much appreciated
If you're developing an app to be used on the Enterprise Grid plan, you can request a sandbox from Slack directly, though it won't contain any test data off the bat.
More information on that here: https://api.slack.com/enterprise/grid/testing.
That being said, you could populate it with information yourself, using a combination of several different Web API methods. Here are a couple methods that may be of use to you:
chat.postMessage - posts a message in a channel
conversations.create - creates a new channel
reactions.add - adds a reaction onto an item
I'm writing a Python program that is trying to monitor my Gmail Inbox. Whenever a new email arrives, my program should receive the actual email content. I think the best way to do this is via Google push notifications using Gmail API.
I have made a topic and subscription, as well as manually sent and received messages using these. I have completed the Google pub-sub setup and have called watch( ) on my Inbox. If I understand this correctly, a successful watch( ) call means that my Inbox will be constantly monitored. Whenever I receive a new email, a message of the form {emailAddress, historyId} should be sent to my topic.
From this, how would I be able to actually get the email content? According to the tutorial, I would have to do something like history.list( ) to get the "change details for the user since their last known historyId." What exactly will these "change details" be? Will they be the actual email content?
Should my next step be to set up a REST pull subscription? I am thinking of using this link:https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/pull so that my program can actually receive the messages sent to my topic.
To get the content of an email after a push notification
As you have seen, the users.watch subscription will send you:
{
"historyId": string,
"expiration": string
}
With this historyId you can call the users.history.list endpoint to get:
{
"history": [
{
"id": "[historyId]",
"messages": [
{
"id": "[MSG ID]",
"threadId": "[THREAD ID]"
}
]
}
]
}
From there you would call the users.messages.get endpoint to get the actual message.
NOTE: For some history IDs you will get more than one message/thread/or event per historyId, so depending on your needs you would need to handle this with your reciever.
There are a few options but you could potentially use a cloud function to receive the notifications.
You could also simply set up a cron job to run your Python script every X minutes, again, depends on your specific needs.
References
users.watch
users.history.list
users.messages.get
There is a defined conversation flow for my agent. Using some metric, at a certain point within that conversation flow, the agent is supposed to prompt something to the user, the user hasn't said anything, the bot isn't reacting, it is initiating letting something know to the user at this point of time.
So from my web search and previous dialogflow forum discussions, 'Events' seemed to be the tool to be able to do this. So I have a Python Django-based web server which takes in and responds to webhooks from my Dialogflow agent. ANd my chatbot interface is an Android app which I made based on the 'Dialogflow-android-client' sample app present in Dialogflow's github account (https://github.com/dialogflow/dialogflow-android-client). With this setup the basic conversation chatbot is working well. Now I am trying to implement the scenario described in the paragraph above.
Now, to do this I implemented sending a POST /query Request to the Dialogflow agent to invoke an event (as given in the Dialogflow documentation: https://dialogflow.com/docs/events#invoking_event_from_webhook). It is successfully invoking the intent which has that particular event associated with it. On the invocation of that intent using EVENT webhook, I get back a json response from the agent back to my server in the format described in the documentation. But the client end (neither the Android app nor the Dialogflow developer dialog check console) is showing the text or speaking out the Output text that the event triggered intent. I am only getting all JSON info at my server, nothing is going to the client app. Why is this? In previous Dialogflow forum discussions, one experienced person said that with Event triggering through webhook, you only get information back to where you initiated the trigger from and nowhere else.Is that true? At that same place it was said the best way to get the response at the client app for the event trigger is to use FollowupEvent tool instead.
So that's what I am doing, in the webhook response from my server for 1 intent that was activated by something the user said, I am including the FollowupEvent info in the response JSON. But still no response from the event triggered intent comes at the client app. I think in this case the intent to be triggered is not getting triggered only, since if it was triggered, a POST webhook request for that intent would have come to the server, which it has not. Why is it not working? What is the resolution?
Here is the JSON being sent to the Dialogflow agent from my server (using FollowupEvent):
{
"contextOut": [],
"speech": " ",
"displayText": " ",
"source": "PSVA-server",
"followupEvent": {
"event": {
"name": "testr",
"data": {}
}
}
}
In my Dialogflow agent, I have created an intent which doesn't have any user_says
example in it, has one event "testr" named in it, has an answer text and 'webhook'
option checked in fulfillment.
And finally is there any better method to implement what I am trying to implement?
I have managed to read the unseen count of Facebook notifications, but was wondering if there is way to mark the notifications as read. I'm using the Facebook API for python. I saw a link that someone has posted in this site but it's expired.
You should set the field: unread=0 in order to mark a notification as read:
import facebook
graph = facebook.GraphAPI(access_token)
graph.put_object("notification_id", "", unread=0)
For more info you can refer to this: Graph API Doc for norfications
Let me know if there is any issue.
I'm trying to figure out an effective way to test how my server handles webhooks from Stripe. I'm setting up a system to add multiple subscriptions to a customer's credit card, which is described on Stripe's website:
https://support.stripe.com/questions/can-customers-have-multiple-subscriptions
The issue I'm having is figuring out how to effectively test that my server is executing the scripts correctly (i.e., adding the correct subscriptions to the invoice, recording the events in my database, etc.). I'm not too concerned about automating the test right now, I'm just struggling to effectively run any good test on the script. Has anyone done this with Django previously? What resources and tools did you use to run these tests?
Thanks!
I did not use any tools to run the tests. Impact the stripe has a FULL API REFERENCE which display the information you have send to them and they also display the error. Stripe is very easy to setup, cheap, and have full details in documentation.
What I did is?
First I create a stripe account. In that account, they will give you:
TEST_SECRET_KEY: use for sending payment and information in stripe (for testing)
TEST_PUBS_KEY: identifies your website when communicating with Stripe (for testing)
LIVE_SECRET_KEY: use for sending payment and information in stripe (for live)
LIVE_PUBS_KEY: identifies your website when communicating with Stripe (for live)
API_VERSION: "2012-11-07" //this is the version for testing only
When you login you will see Documentation at the top. Click the documentation and they will give you step by step tutorial on how to create a form, how to create subscription, how to handle errors and many more.
To check if your script is executing and connecting to stripe. Click FULL API REFERENCE then choose Python. In that page you will see the information you have send and error that you have encountered.
What I really like is, if the Stripe detect an error the system will point out that and give you a solution. The solution is in the left side and checking the information send is on the right side.
Stripe is divided into two worlds: the test mode and the live. In test mode, you can perform creating new customer, add new invoices, set up your subscription, and many more. What ever you do in test mode, is the same when your Stripe is live.
I really love that stripe provides the logs for the web hooks, however, it is difficult to view the error responses from them, so I set up a script using the Requests library. First, I went to the Stripe dashboard and copied one of the requests they were sending.
Events & Webhooks --> click on one of the requests --> copy the entire request
import requests
data = """ PASTE COPIED JSON REQUEST HERE """
# insert the appropriate url/endpoint below
res = requests.post("http://localhost:8000/stripe_hook/", data=data).text
output = open("hook_result.html", "w")
output.write(res)
output.close()
Now I could open hook_result.html and see any django errors that may have come up (given DEBUG=True in django).
In django-stripe-payments I have a test suite that while far from comprehensive is meant to be a start at getting there. What I do is just copy a real webhook's data, scrub it for sensitive data and add it as a data to the test.
testing stripe webhooks is a pain. I don't use Django, so my answer will be more general.
My php webhook handler parses the webhook data and dispatches handler functions accordingly. In my handler class, I set up class properties with legitimate data for all the ids that the test webhooks mangles. Then I have a condition in each of my handler functions that tests for livemode. If false, I replace the mangled ids with legit test ids.
I also have another class property called $fakeLiveMode, which I set to true when I'm testing. This allows me to force the code to process as though in live mode.
So, for example, when testing the customer.subscription.updated event, the plan id and customer id get botched. So in that handler I would do this:
if ($event->livemode === true || $this->fakeLivemode)
{
if ($this->fakeLivemode)
{
// override botched data returned by test webhook
$event->data->object->plan->id = $this->testPlanId;
$event->data->object->customer = $this->testCustomerId;
}
// process webhook
}
Does that help?