-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This boilerplate creates some basic AprilBot functionality for connecting to slack and handling some basic types of interactions. I had to create types for the event handlers for now, though I opened an issue in the Slack sdk in the hopes they might add types [1] to their events. This also swaps out the class-methods-use-this lint rule for a smarter variety, which is probably something that the upstream maintainer should consider adding as well [2]. [1] slackapi/node-slack-sdk#1768 [2] iamturns/eslint-config-airbnb-typescript#344
- Loading branch information
Showing
9 changed files
with
132 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
import { GenericAprilBot } from './GenericAprilBot'; | ||
import { getLogger } from './logger'; | ||
import type { | ||
SocketModeEventPayload, | ||
ReactionAddedEvent, | ||
ReactionRemovedEvent, | ||
MessageEvent, | ||
} from './types'; | ||
|
||
const logger = getLogger(); | ||
|
||
class AprilBot extends GenericAprilBot { | ||
constructor(userToken: string, appToken: string) { | ||
super(userToken, appToken); | ||
logger.debug('AprilBot is constructed'); | ||
} | ||
|
||
public async start() { | ||
await super.start(); | ||
} | ||
protected override handleMessage = ({ | ||
ack, | ||
event, | ||
}: SocketModeEventPayload<MessageEvent>) => { | ||
ack(); | ||
logger.debug(event, 'handleMessage'); | ||
}; | ||
|
||
protected override handleReactionAdded = ({ | ||
ack, | ||
event, | ||
}: SocketModeEventPayload<ReactionAddedEvent>) => { | ||
ack(); | ||
logger.debug(event, 'handleReactionAdded'); | ||
}; | ||
|
||
protected override handleReactionRemoved = ({ | ||
ack, | ||
event, | ||
}: SocketModeEventPayload<ReactionRemovedEvent>) => { | ||
ack(); | ||
logger.debug(event, 'handleReactionRemoved'); | ||
}; | ||
} | ||
|
||
export { AprilBot }; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
interface MessageEvent { | ||
user: string; | ||
type: string; | ||
ts: string; | ||
client_msg_id: string; | ||
text: string; | ||
team: string; | ||
thread_ts?: string; | ||
blocks: MessageBlock[]; | ||
channel: string; | ||
event_ts: string; | ||
channel_type: string; | ||
} | ||
|
||
interface MessageBlock { | ||
type: string; | ||
block_id: string; | ||
elements: BlockElement[]; | ||
} | ||
|
||
interface BlockElement { | ||
type: string[]; | ||
elements: BlockElementElement[]; | ||
} | ||
|
||
interface BlockElementElement { | ||
type: string; | ||
text: string; | ||
} | ||
|
||
export { MessageEvent }; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface ReactionAddedEvent { | ||
type: string; | ||
user: string; | ||
reaction: string; | ||
item: { | ||
type: string; | ||
channel: string; | ||
ts: string; | ||
}; | ||
item_user: string; | ||
event_ts: string; | ||
} | ||
|
||
export { ReactionAddedEvent }; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface ReactionRemovedEvent { | ||
type: string; | ||
user: string; | ||
reaction: string; | ||
item: { | ||
type: string; | ||
channel: string; | ||
ts: string; | ||
}; | ||
item_user: string; | ||
event_ts: string; | ||
} | ||
|
||
export { ReactionRemovedEvent }; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
interface SocketModeEventPayload<T> { | ||
event: T; | ||
ack: () => void; | ||
} | ||
|
||
export { SocketModeEventPayload }; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './MessageEvent'; | ||
export * from './ReactionAddedEvent'; | ||
export * from './ReactionRemovedEvent'; | ||
export * from './SocketModeEventPayload'; |