Bolt-js: import feature/module from another file

Created on 14 Aug 2019  路  9Comments  路  Source: slackapi/bolt-js

Description

I'm sure its probably somewhere and I feel like an idiot for asking, but how do I import features/modules from another file into the app?

i.e. in botkit they use controller.loadModules() is there something similar with bolt?

Didn't see it anywhere in the documentation, happy to be pointed in the right direction or open up a PR once I've grokked it.

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

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [x] documentation related
  • [ ] testing related
  • [ ] discussion

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

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.
OhGodWhereAmI

enhancement question

Most helpful comment

+1 on this, I've scoured all the issues and exhausted all the Google search results, but found nothing on this topic. I'd love to abstract out all my application logic to be separate from my index.js.

All 9 comments

+1 on this, I've scoured all the issues and exhausted all the Google search results, but found nothing on this topic. I'd love to abstract out all my application logic to be separate from my index.js.

+1, glad this is getting attention. I can't seem to find a solution either. Would really like to keep my codebase organized.

@shanedewael is this something that isn't currently possible then hence the enhancement label?

@rparsonsbb Sorry for our very late response here.
I don't think any blockers that prevent developers from organizing code exist. We may be able to come up with some guides or samples, though.

@seratch Yeah, it would be super helpful to share some guides or examples on this :)

@seratch any update on how to do this? I.e. if I want to move all my 'action' function to a different file than my main app.ts. I can't seem to find any documentation about it

@SpencerLawrenceBrown If this is helpful to you, we have done in it in following ways:

import * as features from "./features";

export class SlackApp {
  app: App;

  constructor(expressReceiver: ExpressReceiver) {
    this.app = new App({
      receiver: expressReceiver,
      logLevel: LogLevel.DEBUG,
    });


    for (const f in features) {
      logger.info(`Attaching ${f} to slack app`);
      features[f](this.app);
    }
  }
}

features/index.ts

export * from "./action1";
export * from "./action2";
export * from "./action3";

features/action1

export function appHome(app: App): void {
  app.event("app_home_opened", async ({ event, context, client }) => {

  });

  app.action("action_name",
    async ({ action, ack, body, context, client }) => {
   });
}

@SpencerLawrenceBrown We do not have the official guide for this yet but I personally like @moizjv's way to organize code!

I'm not sure how much helpful this is but let me share a few more examples before closing this issue:

We may revisit this in the future but, at this moment, we are not planning to update the document on this. Let us close this issue now.

Was this page helpful?
0 / 5 - 0 ratings