I have created the simple firebase function for Google assistant but when I try to send HTTP request I got an error in google actions simulator
MalformedResponse
'final_response' must be set.
The next action works properly:
app.intent('Default Welcome Intent', (conv) => {
conv.ask(`What do you want?`);
});
But the next is not working (produce the previous error):
app.intent('turnOff tv', (conv) => {
request('http://someurl.com', (res) => {
conv.ask('Alright, your value is');
});
});
I was installing request module before (npm install request --save).
And I'm using the free firebase account.
How can I make an HTTP request in Firebase function while triggering a Google action from Google home?
Thanks!
Sadly, using the free plan for Google Functions, you cannot trigger a request for an external service other than Google.
The firebase free plan allows outbound networking to Google Services only.
Source: Firebase pricing for details.
Related
Is there any way to track the count of successfully sent push notifications in FCM ? I can see the messages sent using Firebase console but i need to track the number of messages sent via web app to the devices.
I have tried the same using onMessaging event of firebase, tried sending direct hit for google analytics as well from service worker but without any success.
return fetch('https://www.google-analytics.com/collect', {
method: 'post',
body: payloadString
})
Also tried logEvent using following -
const analytics = firebase.analytics();
logEvent(analytics, 'web_notification', {action : 'send'});
No event is getting saved in firebase console. Is there any way I can achieve the same?
You can check those data in BigQuery export. Just link your Firebase app to BigQuery. From there, you can query the messages that were successfully sent.
I have a service account that has successfully made calls to both firebase API and google analytics v4 admin API.
It can create analytics v4 properties through the analytics admin API, but from firebase for some reason it fails.
The reason I'm doing this through firebase is that I need to add app data streams, and that's not possible through the analytics admin API (gotta love google...)
Making the call below as in the docs fails with:
// the response
code: 403,
errors: [
{
message: 'The caller does not have permission',
domain: 'global',
reason: 'forbidden'
}
]
// the call
apiClient.request({
method: 'POST',
url: `https://firebase.googleapis.com/v1beta1/projects/${projectNumber}:addGoogleAnalytics`,
data: JSON.stringify({
analyticsAccountId,
}),
}),
403 errors appears when the email account you are using doesn't have enough permission to process the action you're doing. You must be an Owner for the existing Firebase Project and have the Edit permission for the Google Analytics account, to be able to add Analytics in your project using the API.
I'm a little stuck here.
I'm trying to hook a Calendar Push Notifications (https://developers.google.com/calendar/v3/push) to a Firebase HTTPS Function.
Pratically, I use a FF to create a calendar and I want to watch it for changes.
I authorized my domain and compose a request from the first function using the appspot service account ('#appspot.gserviceaccount.com') with the scope 'https://www.googleapis.com/auth/calendar' but I always received the error message: "Unauthorized WebHook callback channel: https://******.cloudfunctions.net/calendarWebHook"}],"
I'm trying to understand if the service account doesn't have the authorization to create the watcher or the webHook or something else.
I'm in the final stages of development for my new mobile app, but can't seem to find a way to allow Google Play Real-Time Developer Notifications to communicate to a firebase cloud function via the recommended Google Pub/Sub method.
The expected payload flow should go as follows:
User Purchases Subscription via Play Store > Play Store sends R-T Dev Notification to Pub/Sub > Pub/Sub sends message across to firebase cloud function > Cloud function runs with payload.
I currently have an Apple Developer webhook set-up in a similar way, which webhooks a receipt payload to an iOS cloud function I have setup.
During the pub/sub setup phase, the Pub/Sub page asks to verify the cloud function URL, which I cannot do as I am not the true webmaster of cloud function domain, hence halting me about halfway down the 'Add real-time developer notification' docs that google supplies.
Is there a way to get the RT notification to either a Pub/Sub cloud function or a HTTPS cloud function bypassing the google Pub/Sub and going directly to the webhook or another way to complete the flow above?
The ultimate aim is to provide a way to ensure the purchase made is actually a valid purchase, and not a forged request made by someone intercepting the client > server webhook and submitting one of their own accord.
After creating the new topic you DO NOT have to create manually a Pub/Sub subscription as explained in the documentation.
To make it work with firebase you have to deploy a new cloud function like this:
exports.YOUR_FUNCTION_NAME = functions.pubsub.topic('YOUR_TOPIC_NAME').onPublish((message) => {
// Decode the PubSub Message body.
const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;
// Print the message in the logs.
console.log(`Hello ${messageBody || 'World'}!`);
return null;
});
Please note that you need to replace YOUR_FUNCTION_NAME and YOUR_TOPIC_NAME.
When the deploy of this function finish, you will finally find the function in the subscription list.
At this point, you can edit the params of the automatically created subscription, and you will find the url endpoint already filled with an internal url.
Here you can find an example: how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.
Goal
I would like Slack to trigger a Firebase Cloud Function.
Example: A user sends a Slack message, and Firebase Cloud Functions writes part of the message to the Firebase Database.
Tools: Slack API \ Event Subscription, googleapis, nodejs, etc.
Issue
The Slack documentation here describes the challenge response requirement.
Once you receive the event, respond in plaintext with the challenge
attribute value.
However, I'm not sure how to let Firebase know the Slack request is authorized. An HTTP request to Firebase Cloud Functions must include a Firebase ID. I've let googleapis do the work of setting up the Firebase ID, and I don't see a way to alter Slack's initial verification request (if I had an ID to provide)
What's the best way to trigger Firebase with the Slack API?
Getting Slack to verify the Firebase URL is pretty easy.
Solution
Google Firebase Cloud Function
import * as functions from "firebase-functions";
export const helloSlack = functions.https.onRequest((request, response) => {
if (request) {
response.status(200).send(request.body);
} else {
console.log("Request Error...");
throw response.status(500);
}
});
Steps
Deploy your Firebase Cloud Function
Goto https://api.slack.com/apps
Your App > Event Subscriptions > Enable Events
Turn on Events
Enter your Firebase Cloud Functions URL
tl;dr
Slack instructions:
We’ll send HTTP POST requests to [your] URL when events occur. As soon
as you enter a URL, we’ll send a request with a challenge parameter,
and your endpoint must respond with the challenge value.
Cloud Function URL:
https://firebase-slack-adaptor.cloudfunctions.net/helloSlack
To meet the verification challenge, enter your Firebase Cloud Functions URL (example above) in Slack's Request URL field.
Your Firebase Cloud Function should return the body of the Slack request. Slack finds what it needs in request.body and should verify your URL.