-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: [WIP] Convert slackMock.js to TypeScript
- Loading branch information
Showing
38 changed files
with
144 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import type {SlackEventAdapter} from '@slack/events-api'; | ||
|
||
export class TeamEventClient { | ||
private readonly eventAdapter: SlackEventAdapter; | ||
private readonly team: string; | ||
#eventAdapter: SlackEventAdapter; | ||
#team: string; | ||
|
||
// contract: 渡されるeventAdapterは、EventAdapterOptions.includeBodyがtrueでなければならない。 | ||
constructor(eventAdapter: SlackEventAdapter, team: string) { | ||
this.eventAdapter = eventAdapter; | ||
this.team = team; | ||
this.#eventAdapter = eventAdapter; | ||
this.#team = team; | ||
} | ||
|
||
// listen on events against all teams. | ||
onAllTeam(event: string, listener: (...args: any[]) => void): any { | ||
return this.eventAdapter.on(event, listener); | ||
return this.#eventAdapter.on(event, listener); | ||
} | ||
// listen on events against the team. | ||
on(event: string, listener: (...args: any[]) => void): any { | ||
return this.eventAdapter.on(event, (...args: any[]) => { | ||
return this.#eventAdapter.on(event, (...args: any[]) => { | ||
// https://slack.dev/node-slack-sdk/events-api#receive-additional-event-data | ||
// https://github.com/slackapi/node-slack-sdk/blob/3e9c483c593d6aa28f6f5680f287722df3327609/packages/events-api/src/http-handler.ts#L212-L223 | ||
// https://api.slack.com/apis/connections/events-api#the-events-api__receiving-events__events-dispatched-as-json | ||
// args: [body.event, body: {team_id: string}] | ||
if (args[1].team_id === this.team) { | ||
if (args[1].team_id === this.#team) { | ||
listener(...args); | ||
} | ||
}); | ||
} | ||
|
||
// feel free to add any other [Events](https://nodejs.org/api/events.html) methods you want! | ||
} | ||
|
||
// https://stackoverflow.com/a/48953930 | ||
export type TeamEventClientInterface = Pick<TeamEventClient, keyof TeamEventClient>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.