Skip to content

Commit

Permalink
feat(dingtalk): support send private url assets
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Nov 22, 2023
1 parent 9455154 commit e7bf3dd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion adapters/dingtalk/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Context, Dict, h, MessageEncoder } from '@satorijs/satori'
import { DingtalkBot } from './bot'
import FormData from 'form-data'
import { SendMessageData } from './types'
import { Entry } from '@satorijs/server-temp'

export const escape = (val: string) =>
val
Expand Down Expand Up @@ -93,7 +94,16 @@ export class DingtalkMessageEncoder<C extends Context = Context> extends Message
// await this.sendMessage('sampleImageMsg', {
// photoURL: attrs.url
// })
this.buffer += `![${attrs.alt}](${attrs.url})`
if (await this.bot.http.isPrivate(attrs.url)) {
const temp = this.bot.ctx.get('server.temp')
if (!temp) {
return this.bot.logger.warn('missing temporary file service, cannot send assets with private url')
}
const entry: Entry | undefined = await temp.create(attrs.url)
this.buffer += `![${attrs.alt ?? ''}](${entry.url})`
} else {
this.buffer += `![${attrs.alt ?? ''}](${attrs.url})`
}
} else if (type === 'message') {
await this.flush()
await this.render(children)
Expand Down

0 comments on commit e7bf3dd

Please sign in to comment.