I wish to set up the slackbot logic on a google functions environment (serverless computing).
The following are relevant snippets of the code
'use strict'
const functions = require('firebase-functions');
..
const { App } = require('@slack/bolt');
const app = new App({
signingSecret: signingSecret,
token: botToken,
});
..
app.message(({ message, say }) => {
say('hello');
});
exports.funcname = functions.https.onRequest(app);
In the events subscription settings of my slack app I am setting the url to:
https://us-central1-project-id.cloudfunctions.net/funcname/slack/events
However, it gives me an error on checking as: Your URL didn't respond with the value of the challenge parameter.
What could be going wrong?
When I try this on a local server (ngrok) it works. I am not sure how we pass the app to the google functions method. Thanks for the help.
I'm trying to use bolts with Cloud Functions for Firebase. but does not work.
The following code compiles correctly.
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
import {
App,
ExpressReceiver
} from '@slack/bolt'
import { ConsoleLogger } from '@slack/logger'
type AppConfig = {
slack: {
/* eslint camelcase: 0 */
signing_secret: string
token: string
}
}
admin.initializeApp({
credential: admin.credential.applicationDefault()
})
const appConfig = functions.config() as AppConfig
const logger = new ConsoleLogger()
const receiver = new ExpressReceiver({
signingSecret: appConfig.slack.signing_secret,
logger,
endpoints: '/events'
})
const app = new App({
token: appConfig.slack.token,
receiver,
logger,
botId: 'B---',
botUserId: 'U---'
})
export const slackApp = functions.https.onRequest(receiver.app)
But this doesn't work perfect yet.
Because the ExpressReceiver's requestHandler is early returned, Cloud Functions will end. Unable to process message.
In order to resolve this, the requestHandler must wait for the processing of the matched Event Handler to complete.
I haven't checked why the above code examples don't work yet, but my code below surely works on Google Cloud Functions (not sure about Cloud Functions for Firebase yet). ~https://github.com/seratch/slack-app-examples/blob/86bd224476814a42c41c133f9009ea66c0717517/serverless-gcp-template/index.js~
https://github.com/seratch/slack-app-examples/blob/86bd224476814a42c41c133f9009ea66c0717517/serverless-bolt-template/gcp-js/app.js
I may be able to dig this issue deeply when I have time.
I made sure Bolt works on Cloud Functions for Firebase. Here is a working example. https://github.com/seratch/bolt-on-cloud-functions-for-firebase
I'm afraid that you might be using node 8 (the default engine). You need to modify package.json to use node 10. Bolt runs on Node 10+ https://github.com/seratch/bolt-on-cloud-functions-for-firebase/blob/267927e49f12e6b5cdf2cc786f1a553eadaaf9e1/functions/package.json#L12
I noticed that when running Bolt apps using firebase serve (firebase-tools's command to run apps on local machines), async operations such as say don't complete. I guess @k2wanko might mention this issue in his comment.
Personally, I recommend to simply run Bolt apps as an Express app like this. But, if Bolt'll have a large number of users who need to invoke apps using firebase-tools in the future, supporting the specific need would be helpful for many people.
Thanks. Let me check and comment back.
@seratch Thank you for confirming.
Perhaps this code works on cloud because processing is completed within max function duration.
I created a custom receiver to work with both Local Machine and Cloud, but this doesn't work.
https://gist.github.com/k2wanko/4df5501da581b7370d148e6a7429ccdd
Because onIncomingEvent does not wait forlistener to complete.
https://github.com/slackapi/bolt/blob/77431a7c1e57637ac8e15b5cf8005764fac92f53/src/App.ts#L311
Maybe processMiddleware will solve it if it supportsasync/await.
@rrrepos
Thanks for the response. Could you close this issue once you find my sample works for you?
@k2wanko
I'm afraid that I might not understand the things you pointed out yet but my understanding is:
firebase serve, Cloud Functions emulator by Firebase (As I mentioned above, I personally recommend running Bolt as an Express app for local development)If we can make further efforts together to let GCP users to use Bolt much easier, we can discuss it separately in another GitHub issue. 馃檶
@seratch / @k2wanko It tried it on my google functions and it works wonderfully. Thanks. Sorry for the delay in confirming. I am in the thick of another project. I will close this issue.
I'm trying to use the firebase emulator and localtunnel to develop a slack bolt app and not having any success. I guess that is still a problem, however this is generally the way you would work for firebase apps as deploying the code each time is very tedious / time-consuming
one thing to note is that bolt won't work with the FREE firebase plan it seems, as it requires an outbound network request - not just responding to webhooks. took me a while to figure this out...
I made sure Bolt works on Cloud Functions for Firebase. Here is a working example. https://github.com/seratch/bolt-on-cloud-functions-for-firebase
I'm afraid that you might be using node 8 (the default engine). You need to modify
package.jsonto use node 10. Bolt runs on Node 10+ https://github.com/seratch/bolt-on-cloud-functions-for-firebase/blob/267927e49f12e6b5cdf2cc786f1a553eadaaf9e1/functions/package.json#L12
Just followed the example you have here for a bolt application on firebase cloud function and I am having no luck with this.
running into a 404
@dozievouchrapp
What do you mean by 404 errors? I've updated the sample project and verified it works two weeks ago. So, it should be up to date. If you have questions about the sample, could you ask them in the repo's issue tracker? I can help you out.
@dozievouchrapp
What do you mean by 404 errors? I've updated the sample project and verified it works two weeks ago. So, it should be up to date. If you have questions about the sample, could you ask them in the repo's issue tracker? I can help you out.
My mistake I had the wrong token when testing