Goal
A Slack Event-Subscription event is hitting my Firebase Endpoint, and then, a Firebase Cloud Function is using the dialog_open
endpoint to open a dialog in Slack with some values from Firebase.
Issue
When the Firebase Cloud function hits Slack's dialog_open
endpoint, I get errors in the console log.
I am getting body: { ok: false, error: 'trigger_expired' }
However, the logs in Firebase show the round-trip is less than 500 milliseconds. But, I don't see the trigger ID which will log to the trigger_id from the first request (see code below).
4:57:12.443 PM | info | helloWorld | body: { ok: false, error: 'trigger_expired' }
4:57:04.163 PM | outlined_flag | helloWorld | Function execution took 254 ms, finished with status code: 200
4:57:03.910 PM | outlined_flag | helloWorld | Function execution started
When I trigger the Slack event a second, third, or fourth time after a fresh deploy, I get body: { ok: false, error: 'invalid_trigger' }
5:31:29.757 PM helloWorld body: { ok: false, error: 'invalid_trigger' }
5:31:28.744 PM helloWorld Function execution took 9 ms, finished with status code: 200
5:31:28.740 PM helloWorld json.trigger_id: "405615464868.7467239747.e706f2732257c541c445ad3938a29fd3"
5:31:28.735 PM helloWorld Function execution started
This also happens fast enough (9ms), but a different trigger error, AND this time I do see the json.trigger_id
from the Slack Event-Subscription event.
Last thing, I tried JSON.stringify:
trigger_id: JSON.stringify(json.trigger_id),
Now the logs and error are different:
5:33:24.512 PM | info | helloWorld | body: { ok: false, error: 'internal_error' }
5:33:23.565 PM | outlined_flag | helloWorld | Function execution took 13 ms, finished with status code: 200
5:33:23.559 PM | info | helloWorld | json.trigger_id: "406895248231.7467239747.7490e460213b3d65a44eef9f2e30c168"
5:33:23.553 PM | outlined_flag | helloWorld | Function execution started
Question
I must be doing something dumb. Any guesses what is wrong with my trigger_id
?
Code
Here is the Firebase Cloud Function:
import * as rp from "request-promise";
import * as functions from "firebase-functions";
export const helloWorld = functions.https.onRequest((request, response) => {
return new Promise((_resolve, _reject) => {
let json = JSON.parse(request.body.payload);
console.log("json.trigger_id:", json.trigger_id);
const options = {
method: "POST",
uri: "https://slack.com/api/dialog.open",
body: {
trigger_id: json.trigger_id,
dialog: {
callback_id: json.callback_id,
title: "Request a Ride",
submit_label: "Request",
elements: [
{ type: "text", label: "Pickup Location", name: "loc_origin" },
{ type: "text", label: "Dropoff Location", name: "loc_destination" }
]
}
},
json: true,
headers: {
"Content-type": "application/json; charset=utf-8",
Authorization:
"Bearer xoxp-secret"
}
};
rp(options)
.then(function(body) {
console.log("body:", body);
})
.catch(function(err) {
console.log("err:", err);
});
return response.status(200).json({ message: "Hello from Firebase" });
}).catch(err => response.status(500).send(err));
});