Skip to content

Commit 3d3157e

Browse files
feat(telegram): add metadata to sticker (#347)
1 parent 7b73eeb commit 3d3157e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

adapters/telegram/src/bot.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ export class TelegramBot<C extends Context = Context, T extends TelegramBot.Conf
160160
}
161161
}
162162

163-
async $getFileFromPath(filePath: string) {
163+
async $getFileFromPath(filePath: string, extra?: Record<string, any>) {
164164
if (this.server) {
165-
return { src: `${this.server}/${filePath}` }
165+
return { ...extra, src: `${this.server}/${filePath}` }
166166
}
167167
let { type, data } = await this.$getFile(filePath)
168168
if (type === 'application/octet-stream') {
169169
type = (await FileType.fromBuffer(data))?.mime
170170
}
171171
const base64 = `data:${type};base64,` + Binary.toBase64(data)
172-
return { src: base64 }
172+
return { ...extra, src: base64 }
173173
}
174174

175175
private async setAvatarUrl(user: Universal.User) {

adapters/telegram/src/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ export async function decodeMessage(
252252
if (file.file_path.endsWith('.tgs')) {
253253
throw new Error('tgs is not supported now')
254254
}
255-
segments.push(h('img', await bot.$getFileFromPath(file.file_path)))
255+
segments.push(h('img', await bot.$getFileFromPath(file.file_path, {
256+
id: data.sticker.file_id,
257+
uniqueId: data.sticker.file_unique_id,
258+
setName: data.sticker.set_name,
259+
})))
256260
} catch (e) {
257261
bot.logger.warn('get file error', e)
258262
segments.push(h('text', { content: `[${data.sticker.set_name || 'sticker'} ${data.sticker.emoji || ''}]` }))

0 commit comments

Comments
 (0)