Skip to content

Commit

Permalink
feat(core): transform components before before-send
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 2, 2023
1 parent 53a7e20 commit decc3e4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export abstract class MessageEncoder<C extends Context = Context, B extends Bot<
this.session[key] = this.options.session[key]
}
await this.prepare()
this.session.elements = h.normalize(content)
const session = this.options.session ?? this.session
this.session.elements = await session.transform(h.normalize(content))
const btns = h.select(this.session.elements, 'button').filter(v => v.attrs.type !== 'link' && !v.attrs.id)
for (const btn of btns) {
const r = Math.random().toString(36).slice(2)
btn.attrs.id ||= r
if (typeof btn.attrs.action === 'function') this.bot.callbacks[btn.attrs.id] = btn.attrs.action
}
if (await this.session.app.serial(this.session, 'before-send', this.session, this.options)) return
const session = this.options.session ?? this.session
await this.render(await session.transform(this.session.elements))
await this.render(this.session.elements)
await this.flush()
if (this.errors.length) {
throw new AggregateError(this.errors)
Expand Down

0 comments on commit decc3e4

Please sign in to comment.