Skip to content

Commit

Permalink
feat(discord): support sending voice messages (#264)
Browse files Browse the repository at this point in the history
Co-authored-by: Maiko Sinkyaet Tan <maiko.tan.coding@gmail.com>
Co-authored-by: idanran <96647698+idanran@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 20, 2024
1 parent 8737af9 commit df3ba5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adapters/discord/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class DiscordMessageEncoder<C extends Context = Context> extends MessageE
const { filename, data, mime } = await this.bot.ctx.http.file(attrs.src || attrs.url, attrs)
const form = new FormData()
const value = new Blob([data], { type: mime })
form.append('file', value, attrs.file || filename)
// https://discord.com/developers/docs/reference#uploading-files
form.append('files[0]', value, attrs.file || filename)
form.append('payload_json', JSON.stringify(payload))
return this.post(form)
}
Expand Down Expand Up @@ -300,7 +301,15 @@ export class DiscordMessageEncoder<C extends Context = Context> extends MessageE
} else if (type === 'audio') {
await this.sendAsset('file', attrs, {
...this.addition,
content: this.buffer.trim(),
content: '',
attachments: [
{
waveform: '', // base64 encoded bytearray representing a sampled waveform
id: 0,
duration_secs: attrs.duration ?? 0,
},
],
flags: Message.Flag.IS_VOICE_MESSAGE,
})
this.buffer = ''
} else if (type === 'author') {
Expand Down
4 changes: 4 additions & 0 deletions adapters/discord/src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export namespace Message {
LOADING = 1 << 7,
/** this message failed to mention some roles and add their members to the thread */
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8,
/** this message will not trigger push and desktop notifications */
SUPPRESS_NOTIFICATIONS = 1 << 12,
/** this message is a voice message */
IS_VOICE_MESSAGE = 1 << 13,
}

/** https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure */
Expand Down

0 comments on commit df3ba5a

Please sign in to comment.