Firebase Send Message to Multiple Topics - firebase

I've been trying to send cloud messages to users who subscribed to multiple topics through an API call (POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send) with the following body:
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer MY_ACCESS_TOKEN`
},
body: {
"message": {
"condition": "'cat' in topics || 'dog' in topics",
"notification": {
"title": "Message Title",
"body": "Message Body"
}
}
}
}
I wrote this config according to the FCM documentation. I can get a response similar to this:
{
"name": "projects/myproject-b5ae1/messages/5735743068807585451"
}
but no messages were received by any devices.
I've used the access token for other APIs, which works. I'm also aware that the FCM documentation also provided a different body for the cURL request, which I also tried but not working.
The weird thing is if I only provide one topic in the condition, a message is actually successfully sent to subscribed devices. Am I writing something wrong?
I've already referenced other solutions on Stackoverflow but everything is still not working:
Firebase API call with multiple topics in condition
How to send FCM Push Notifications to multiple topics

After talking to Firebase Support, they pointed out the problem I'm having here is a known bug they are still trying to fix. And there's no specific timeline for a fix yet.
Therefore, there's no problem with my code and I'll have to figure out a workaround myself if I really want to use the "||"(OR) operator.
My current workaround is keep track of subscribers with a database (since Firebase doesn't offer subscribers querying), then implement the OR condition myself by finding a union of subscribers to different topics.
P.S. I just don't get why the downvotes, I actually found a bug here and referenced all the solutions I could found on SO before asking the question here.

Related

How do you respond to a thread in Google Chat from an incoming webhook?

There's a thread that my webhook has previously created that it wants to reply to. Is this possible using a webhook? It seems to be possible with a bot, see this answer:
https://stackoverflow.com/a/58657945/3832377
But I can't find any documentation on doing it from a webhook. As I've created the original message in the thread, I can guarentee a consistent threadId.
I tried to send a body that looked like:
{
"cards": [/* a card */]
"thread": { "name": "some_thread_name" }
}
But received a 500 error.
Documentation: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create
States you have to add the threadKey as a query parameter, not in the request body.

FCM formatting issue

I'm sending to Firebase Cloud Messaging with the following:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=[SERVER_KEY] (The one found in Firebase Project>Settings>Cloud Messaging
Body:
{
"notification" = {
"title": "Title",
"text": "Your Text",
"sound": "default",
"badge": "1"
},
"to" = "a4fbc860-23fd-4ffc-95b7-11c90d8db320" (The Device ID from the hand held)
}
When I send this I continually receive: {"results":[{"error":"InvalidRegistration"}]}
I'm sure it's something simple that I'm missing. The docs aren't very clear on what elements are required and the nomenclature is different between the error messages and the Firebase site. I've tried to swap out "registration_ids" with "to" (using the array, of course), but the result is the same.
When sending to a single device, "to" field should specify an FCM registration token, not a Device ID. You can retrieve the registration token using FirebaseInstanceId.getInstance().getInstanceId() method.
This token looks like two strings, a short and a long one, separated by a colon, e.g. "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
Links to relevant documentation:
Registration token
Legacy HTTP Protocol errors

Telegram `setTyping` API call

I'm trying to set my bot's typing status by sending the following POST request (based on the API docs):
https://api.telegram.org/bot{{botToken}}/setTyping
{
peer: {{chat_id}},
typing: true,
action: 'sendMessageTypingAction'
}
I've tried a few variations of it, such as changing the url to be /messages.setTyping and sending the action as {"_":"sendMessageTypingAction"} as seen here, but all I get is:
{
"ok": false,
"error_code": 404,
"description": "Not Found: method not found"
}
Anyone know what I'm doing wrong?
Thanks to #tashakori for pointing me in the right direction towards the Bot API. For posterity, what I needed to do was:
https://api.telegram.org/bot{{botToken}}/sendChatAction
{
chat_id: {{chatId}},
action: 'typing'
}
The link you have mentioned above belongs to Telegram Core APIs which is used for handling ordinary accounts of Telegram. These so-called Core APIs are not related to Telegram Bot APIs.
The only API that is somehow similar to SetTyping for bots is AnswerCallbackQuery, which can be used only when responding to the user's interaction with inline keyboards. (you can send a text to the user, saying that there is a process running in the background and whenever the user's answer is ready, you can send it using APIs like sendMessage)

Actions on Google responds with "Sorry, I didn't get any response."

I am following this code lab Facts about You: Build a conversational app for the Google Assistant
I had it working once but must have done something wrong because now all. To be 100% clear i have deleted everything on my pc downloaded the code from Git again deleted the project in actions console deleted the project in api.ai. This is the result of a completely new install. I have not changed anything in the code lab.
"Sorry, I didn't get any response."
The request apears to be sending corectly
From actions test:
{
"conversationToken": "CiZDIzU5Ym...",
"debugLevel": 1,
"inputType": "KEYBOARD",
"locale": "en-US",
"mockLocation": {
"city": "Mountain View",
"coordinates": {
"latitude": 37.421980615353675,
"longitude": -122.08419799804688
},
"formattedAddress": "Googleplex, Mountain View, CA 94043, United States",
"zipCode": "94043"
},
"query": "tell me about cats",
"surface": "GOOGLE_HOME"
}
Received in fire-base
[{"name":"actions.capability.AUDIO_OUTPUT"}]},"inputs":[{"rawInputs":[{"query":"tell me about cats","inputType":"VOICE"}],"arguments":[{"rawText":"tell me about cats","textValue":"tell me about cats","name":"text"}],"intent":"actions.intent.TEXT"}],"user":{"locale":"en-US","userId":"AETml1RzwqyijfbawqjZkRSXz-P1"},"device":{},"conversation":{"conversationId":"1504878811393","type":"ACTIVE","conversationToken":"[\"_actions_on_google_\",\"choose_fact-followup\"]"}}},"id":"3b97e239-346f-49a2-a106-96cfb6f69e92","timestamp":"2017-09-08T13:58:29.99Z","lang":"en","result":{"source":"agent","resolvedQuery":"tell me about cats","speech":"","action":"tell.cat.fact","actionIncomplete":false,"parameters":{},"contexts":[{"name":"_actions_on_google_","parameters":{"category.original":"headquarters","category":"headquarters","facts":{"content":{"headquarters":["Google has over 10 fitness facilities in its main campus."],"history":["Google was founded in 1998.","Google was founded by Larry Page and Sergey Brin.","Google went public in 2004.","Google has more than 70 offices in more than 40 countries."]}}},"lifespan":98},{"name":"actions_capability_audio_output","parameters":{},"lifespan":0},{"name":"google_assistant_input_type_voice","parameters":{},"lifespan":0},{"name":"choose_cats-followup","parameters":{},"lifespan":2}],"metadata":{"intentId":"14df3938-3776-477c-811c-d1758ecd15cb","webhookUsed":"true","webhookForSlotFillingUsed":"false","nluResponseTime":19,"intentName":"choose_cats"},"fulfillment":{"speech":"","messages":[{"type":0,"speech":""}]},"score":1},"status":{"code":200,"errorType":"success"},"sessionId":"1504878811393"}
Response returned to actions
{
"audioResponse": "//NExAARAA...",
"conversationToken": "CiZDIzU5Ym...",
"expectUserResponse": true,
"response": "Sorry, I didn't get any response.",
"visualResponse": {
"visualElements": []
}
}
I must be missing something. Firebase is receiving the request its just not responding correctly.
training image
That error on appears if your web hook doesn't provide a response to the assistant. The cloud function has been triggered or has timed out and not returned the JSON back to assistant to parse. Check to see what the output of the cloud function is and check it against the API.AI web hook format here https://developers.google.com/actions/reference/v1/apiai-webhook
It should look something like this:
{
"speech": "...", // ASCII characters only
"displayText": "...",
"data": {
"google": {
"expect_user_response": true,
"is_ssml": true,
"permissions_request": {
"opt_context": "...",
"permissions": [
"NAME",
"DEVICE_COARSE_LOCATION",
"DEVICE_PRECISE_LOCATION"
]
}
}
},
"contextOut": [...],
}
I think this is something on the Google's end. My application have been running on production for more than a week. Based on the logs everything was fine till 6 hours ago but since that the users don't get any answer back.
If I request on the API.AI the response is okay so it's not the firebase/fullfillment causing the issue.
Checked other applications some had the same problem some had no problem at all. Not sure what we can do here.
Errors like this are usually caused by a syntax error or other problem in your Firebase Function after you've updated it. There are a few good approaches to diagnosing problems like this:
Check the Firebase function log. If there is an error, it will almost certainly show up here.
From the command line you can use firebase functions:log to see the most recent logging messages. You can also use the console to view the logs by going to console.firebase.com, selecting the project, selecting Functions, and then the Logs tab.
If there isn't an error, it becomes more of a logic problem. Adding your own logs via console.log(), console.info(), or console.error()
Many times the logs will indicate the function is timing out after 60 seconds when you think you're returning things by then. Make sure you are completing any callbacks and calling assistant.ask() or assistant.tell() (or one of their cousins) to make sure they're being called.
After posting a question on the Google+ actions group. I got a response back from Google.
Actions Bug There is currently a bug in the Actions Platform that
might result in unexpected error messages when running your apps.
We are currently testing a fix and hope to have that rolled out soon.
As of 10 minutes ago it is working again. The code was correct all along.

Push Notifications to tags in BlueMix

I am trying to use the messages service in the Bluemix Services Push REST API to send a push notification to users who are subscribed to previously created tags. The problem is that when I send a notification to multiple tags, if a user is registered to more than one of those tags he is receiving the same notification multiple times.
The API says this:
tagNames (Array[string], optional): Send notification to the devices that have subscribed to any of these tags
So I understand that the user should only receive one notification, instead of what is happening.
My call looks like this:
{
"message": {
"alert": "Text notification",
},
"target": {
"tagNames": ["TAG1","TAG2","TAG3","TAG4","TAG5","TAG6","TAG7"]
},
"settings": {
"apns": {
"badge": 1,
"sound": "UILocalNotificationDefaultSoundName"
}
}
}
Confirmed with the Bluemix Push development team that this is indeed a defect in the service and you should only be receiving one notification in this instance. The team has created a defect for the issue and once it has been resolved and pushed to production I'll update this answer with whatever additional information or changes in usage come from the fix.
Thank you very much for bringing this to our attention

Resources