Skip to content

Commit

Permalink
feat(slack): allow receiving file/audio/video/image (#573)
Browse files Browse the repository at this point in the history
* add files support for slack v1

* feat(slack): allow receiving file/audio/video/image
  • Loading branch information
davidvitora authored Jul 31, 2023
1 parent 89db5ac commit 167a9c3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 261 deletions.
24 changes: 12 additions & 12 deletions packages/channels/src/slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

### Receiving

| Channels | Slack | Details |
| ------------- | :---: | :------ |
| Text || |
| Quick Reply || |
| Postback || |
| Say Something || |
| Voice | | |
| Image | | |
| File | | |
| Audio | | |
| Video | | |
| Location || |
| Channels | Slack | Details |
| ------------- | :---: | :---------- |
| Text || |
| Quick Reply || |
| Postback || |
| Say Something || |
| Voice | | Private URL |
| Image | | Private URL |
| File | | Private URL |
| Audio | | Private URL |
| Video | | Private URL |
| Location || |
34 changes: 29 additions & 5 deletions packages/channels/src/slack/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,23 @@ export class SlackApi extends ChannelApi<SlackService> {
}

if ('user' in message) {
await this.service.receive(
scope,
{ identity: '*', sender: message.user, thread: message.channel },
{ type: 'text', text: message.text }
)
if ('files' in message && message.files?.length) {
for (const file of message.files) {
await this.service.receive(
scope,
{ identity: '*', sender: message.user, thread: message.channel },
{ type: this.mapMimeTypeToStandardType(file.mimetype), url: file.url_private, title: file.title }
)
}
}

if (message.text?.length) {
await this.service.receive(
scope,
{ identity: '*', sender: message.user, thread: message.channel },
{ type: 'text', text: message.text }
)
}
}
}

Expand Down Expand Up @@ -163,6 +175,18 @@ export class SlackApi extends ChannelApi<SlackService> {
payload: action.selected_option.value
})
}

private mapMimeTypeToStandardType(mimeType: string) {
if (mimeType?.startsWith('image/')) {
return 'image'
} else if (mimeType?.startsWith('video/')) {
return 'video'
} else if (mimeType?.startsWith('audio/')) {
return 'audio'
} else {
return 'file'
}
}
}

interface SlackActionHandler<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"pg": "^8.7.1",
"redlock": "^4.2.0",
"semver": "^7.3.5",
"sqlite3": "^5.0.2",
"sqlite3": "^5.0.8",
"uuid": "^8.3.2",
"yn": "^4.0.0"
}
Expand Down
Loading

0 comments on commit 167a9c3

Please sign in to comment.