slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.73k stars 390 forks source link

How do I deploy on Azure Function App? #1275

Closed ankushdutt closed 2 years ago

ankushdutt commented 2 years ago

Description

I tried following this guide: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2. I installed this VS Code extension and generated the starter function code. After editing the index.js, I ran the app locally and it started listening on http://localhost:7071/api/slack-app instead of http://localhost:7071/slack/events. I tried using ngrok's exposed url for these in the request URL for slash commands. For /slack/events, I am getting the “dispatch_failed” error and for /api/slack-app, I am getting nothing (no text and no error on slack) but status 200.

My index.js is:

const { App } = require("@slack/bolt");

module.exports = async function (context) {
  const app = new App({
    token: process.env.SLACK_BOT_TOKEN,
    signingSecret: process.env.SLACK_SIGNING_SECRET,
  });
  app.command("/do-something", async ({ command, ack, respond }) => {
    await ack();
    await respond({
      response_type: "in_channel",
      text: "some text"  
    })
  })
  (async () => {
    await app.start(process.env.PORT || 3000);
    console.log(`⚡️ Bolt app is running!`);
  })();
}

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])

filmaj commented 2 years ago

Hey @ankushdutt thanks for writing in.

Unfortunately I am not familiar with MSFT Azure so I can't provide much help on that front.

A dispatch_failed error from Slack means requests from Slack are not able to be delivered to your application. Sounds like there is some confusion around what URL path events should be dispatched to. I'm not sure why the path would be changing, Bolt by default listens to events on the /slack/events URL path.

Without seeing your application code and configuration (include things like ngrok config and what you are running locally), as well as without seeing any logs, it is difficult for me to help.

seratch commented 2 years ago

Hi @ankushdutt, the default app.start() method does not work for any FaaS handlers.

Unfortunately, we don't support Azure Functions out-of-the-box and we're not planning to add the support at least in the short term. However, if you implement your own receiver for Azure compatibility in a similar way with the AwsLambdaReceiver and pass the receiver to App constructor, your exported function can work.

For your information, back in 2020, I've implemented a simple Python adapter (in bolt-python, adapters are equivalent to receivers in bolt-js) for Azure Functions: https://github.com/seratch/bolt-python/commit/b64eaa05d927cc85ec9f360eb1e3a5c12530d5b7 As long as Azure hasn't introduced breaking changes after that, the example code should still work. If you're fine with bolt-python instead, trying the code out may be a good first step.

I hope this helps! As we don't officially support Azure Functions, we cannot take any further actions here. If everything is clear now, would you mind closing this issue?

ankushdutt commented 2 years ago

Thanks for directing me in the right direction. I will close this issue now.

janssen-io commented 8 months ago

@seratch Would Slack be open to a PR to implement a receiver for Azure Functions?

seratch commented 8 months ago

Hi @janssen-io, thanks for your interest! However, we don't have plans to add an Azure Functions receiver to the built-in ones. If you implement the recevier as your own project, please share it with us!