Browse Source

- output info to console

- fix chat_type
master
pimhwang 1 year ago
parent
commit
786f5f8be3
  1. 2
      src/index.ts
  2. 12
      src/message.ts
  3. 2
      src/server.ts

2
src/index.ts

@ -4,8 +4,8 @@ import * as Potato from './types' @@ -4,8 +4,8 @@ import * as Potato from './types'
export { Potato }
export * from './bot'
export * from './polling'
export * from './message'
export * from './polling'
export * from './server'
export * from './utils'

12
src/message.ts

@ -37,7 +37,7 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> { @@ -37,7 +37,7 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> {
constructor(bot: PotatoBot, channelId: string, guildId?: string, options?: Universal.SendOptions) {
super(bot, channelId, guildId, options)
const chat_id = guildId || channelId
this.payload = { chat_id, parse_mode: 'html', caption: '' }
this.payload = { chat_id, chat_type: Universal.Channel.Type.DIRECT, parse_mode: 'html', caption: '' }
if (guildId && channelId !== guildId) this.payload.message_thread_id = +channelId
}
@ -55,7 +55,7 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> { @@ -55,7 +55,7 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> {
}
const method = await appendAsset(this.bot, form, this.asset)
const result = await this.bot.internal[method](form as any)
await this.addResult(result)
//await this.addResult(result)
delete this.payload.reply_to_message_id
this.asset = null
this.payload.caption = ''
@ -66,8 +66,10 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> { @@ -66,8 +66,10 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> {
// send previous asset if there is any
await this.sendAsset()
} else if (this.payload.caption) {
console.info('reply:')
console.info(this.payload);
const result = await this.bot.internal.sendTextMessage({
chat_type: 1,
chat_type: parseInt(this.payload.chat_type),
chat_id: parseInt(this.payload.chat_id),
text: this.payload.caption
// parse_mode: this.payload.parse_mode,
@ -75,7 +77,9 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> { @@ -75,7 +77,9 @@ export class PotatoMessageEncoder extends MessageEncoder<PotatoBot> {
// message_thread_id: this.payload.message_thread_id,
// disable_web_page_preview: !this.options.linkPreview,
})
await this.addResult(result)
console.info('result:')
console.info(result)
//await this.addResult(result)
delete this.payload.reply_to_message_id
this.payload.caption = ''
}

2
src/server.ts

@ -22,6 +22,8 @@ export class HttpServer extends Adapter<PotatoBot> { @@ -22,6 +22,8 @@ export class HttpServer extends Adapter<PotatoBot> {
const bot = this.bots.find(bot => bot.selfId === selfId)
if (!(bot?.config?.token === token)) return ctx.status = 403
ctx.body = 'OK'
console.info('received:')
console.info(payload);
await handleUpdate(payload, bot)
})

Loading…
Cancel
Save