dialogflow hangouts chat integration no response using actions-sdk - firebase

When connecting dialogflow with hangouts chat I am getting normal responses set in dialogflow. But messages from the webhook running on google actions sdk is not returning messages.
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
const {dialogflow, BasicCard, Permission, Suggestions,} = require('actions-on-google');
app.intent('id', (conv, {name}) =>
{
conv.close(`People here are always available.So,you can call ${name} anytime`)
});
This works with google assistant and webchat. Only with Google chat the response is empty.

The actions-on-google library only works with the Google Assistant.
For other integrations, including Facebook, Slack, and Hangouts Chat, you need to either use the dialogflow-fulfillment library, or respond with JSON directly.

Related

Track Firebase Push notification for web in console

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.

Firebase Cloud Function not Publishing

I am trying to write a cloud function which gets executed every time a sensor reading in the collection "sensor-readings" gets created:
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createNotification = functions.firestore
.document('sensor-readings/{sensorId}')
.onCreate((snap, context) => {
const payload = {
notification: {
title: 'New news',
body: "Body Test"
}
};
// perform desired operations ...
return admin.messaging().sendToTopic("topic",payload);
});
The cloud function gets executed everytime a sensor reading is created but when I try to use
gcloud pubsub subscriptions pull --auto-ack MySub
to test the outcome of the function, there is no message being published to the topic.
Any ideas?
Thanks
This code is working with a product called Firebase Cloud Messaging, which is meant for sending message to web and mobile applications:
admin.messaging().sendToTopic("topic",payload);
But your command line is working with Google Cloud Pubsub, which is a completely different product:
gcloud pubsub subscriptions pull --auto-ack MySub
You can't use FCM to send messages to a pubsub topic. Again, they are completely different. And you can't use gcloud to see what's happening with FCM messages. You would need to do that in your web or mobile app.
If you want to send a messages to a pubsub topic, you should use the Google Cloud SDK for that, not the Firebase Admin SDK.

How to Connect Google Play Real-Time Developer Notifications to Firebase Cloud Function via Pub/Sub?

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.

Http request not working in Firebase webhook for google assistant

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.

Slack API Event Subscription to trigger Firebase 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.

Resources