koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.54k stars 248 forks source link

Bug: KOOK发送 CardMessage 失败 #1132

Closed maxoyed closed 1 year ago

maxoyed commented 1 year ago

Describe the bug

参考 #341 的方案,将 segment 改为 h,发送之后没有反应

Steps to reproduce

await session.send( h('card', { content: JSON.stringify({ type: 'card', theme: 'primary', size: 'lg', modules: modules, }), }) )

Expected behavior

正常发送 KOOK 的 CardMessage

Screenshots

No response

Versions

Additional context

No response

CyanChanges commented 1 year ago

难道 segment 不等于 h

maxoyed commented 1 year ago

难道 segment 不等于 h

发了没反应😂直接发文本是可以的

maxoyed commented 1 year ago

解决了,使用 bot.internal.createMessage 就能发送卡片消息,其他的 KOOK API 也可以调用,参考代码:

const bot = (session.bot as KookBot)
    const res = await bot.internal.getUserView({
      user_id: session.userId
    })
    console.log({ res })
    bot.internal.createMessage({
      type: Type.card,
      target_id: session.channelId,
      content: JSON.stringify([
        {
          "type": "card",
          "theme": "secondary",
          "size": "lg",
          "modules": [
            {
              "type": "section",
              "text": {
                "type": "plain-text",
                "content": "您是否认为\"KOOK\"是最好的语音软件?"
              },
              "mode": "right",
              "accessory": {
                "type": "button",
                "theme": "primary",
                "text": {
                  "type": "plain-text",
                  "content": "完全同意"
                }
              }
            }
          ]
        }
      ])
    })
MaikoTan commented 1 year ago

Koishi has no a card element, so it is not surprising that you cannot use h or the deprecated segment.