Skip to content

Commit

Permalink
feat(telegram): segment handling enhancement (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anillc committed Mar 22, 2021
1 parent 37aec59 commit 19f253e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/adapter-telegram/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export class TelegramBot extends Bot {
payload.photo = ''
}
payload.photo = node.data.url || node.data.file
} else {
payload.caption += '[Unsupported message]'
}
}
if (payload.photo) {
Expand Down
28 changes: 21 additions & 7 deletions packages/adapter-telegram/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,32 @@ export default class HttpServer extends Adapter<'telegram'> {
body.messageId = message.messageId.toString()
body.type = 'message'
body.timestamp = message.date
// TODO convert video message
let msg = message.text || ''
msg += message.caption || ''
let msg
if (message.text) {
msg = message.text
} else if (message.caption) {
msg = message.caption
} else {
msg = ''
}
if (message.photo) {
const fid = message.photo[0].fileId
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += ` [CQ:image,file=${fid},url=${endpoint}/file/bot${token}/${data.result.file_path}]`
}
if (message.sticker) {
msg += segment.image(`${endpoint}/file/bot${token}/${data.result.file_path}`)
} else if (message.sticker) {
const fid = message.sticker.fileId
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += ` [CQ:image,file=${fid},url=${endpoint}/file/bot${token}/${data.result.file_path}]`
msg += segment.image(`${endpoint}/file/bot${token}/${data.result.file_path}`)
} else if (message.animation) {
const fid = message.animation.fileId
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += segment.image(`${endpoint}/file/bot${token}/${data.result.file_path}`)
} else if (message.video) {
const fid = message.video.fileId
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += segment.video(`${endpoint}/file/bot${token}/${data.result.file_path}`)
} else if (!message.text) {
msg += '[Unsupported message]'
}
for (const entity of message.entities || []) {
if (entity.type === 'mention') {
Expand Down

0 comments on commit 19f253e

Please sign in to comment.