Skip to content

Commit

Permalink
feat(teams): send attachments to core
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvitora committed Jan 4, 2024
1 parent 5b042ea commit 463be9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
12 changes: 12 additions & 0 deletions packages/channels/src/base/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export class ChannelApi<TService extends ChannelService<any, any>> {
makeUrl(callback: (scope: string) => Promise<string>) {
this.urlCallback = callback
}

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'
}
}
}

export type Middleware<T> = (req: T, res: Response, next: NextFunction) => Promise<any>
Expand Down
12 changes: 0 additions & 12 deletions packages/channels/src/slack/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ 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
10 changes: 5 additions & 5 deletions packages/channels/src/teams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
| Quick Reply || |
| Postback || |
| Say Something || |
| Voice | | |
| Image | | |
| File | | |
| Audio | | |
| Video | | |
| Voice | | |
| Image | | |
| File | | |
| Audio | | |
| Video | | |
| Location || |
11 changes: 11 additions & 0 deletions packages/channels/src/teams/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ export class TeamsApi extends ChannelApi<TeamsService> {
const endpoint = { identity: '*', sender: activity.from.id, thread: convoRef.conversation!.id }
const text: string | undefined = activity.value?.text || activity.text

if (activity?.attachments?.length) {
for (const attachment of activity.attachments) {
const { contentType, name, contentUrl } = attachment
await this.service.receive(scope, endpoint, {
type: this.mapMimeTypeToStandardType(contentType),
url: contentUrl,
title: name
})
}
}

if (!text) {
return
}
Expand Down

0 comments on commit 463be9f

Please sign in to comment.