Coder Social home page Coder Social logo

Comments (3)

dosubot avatar dosubot commented on June 10, 2024 2

🤖

Hi @wushd! I'm Dosu, a friendly bot here to help you out with your questions and issues on Wechaty while we wait for a human maintainer. I'm here to make your experience with Wechaty as smooth as possible. It's nice to meet you!

是的,可以改变在Wechaty发送群消息时@人的位置。@人的位置取决于你在say方法中放置联系人的位置。如果你想把它放在文字的最后面,可以在文字后面放置联系人。以下是一个例子:

const contact = await bot.Contact.find({name: 'lijiarui'}) // 将'lijiarui'更改为房间的任何成员
await room.say('Hello world!', contact)

在这个例子中,'Hello world!'是消息,contact是你想要@的联系人。@将被放在文本的最后,因为它在say方法中被放在了文本后面。

关于say方法在Wechaty中如何处理消息中@提及的位置,say方法通过接受一个可选的mention参数来处理消息中@提及的位置。这个参数可以是一个ContactInterface对象或一个ContactInterface对象的数组。当提供了这个参数时,提到的联系人将在消息中被@。

这是相关的代码部分:

/**
 * 回复文本或媒体文件消息给发送者。
 *
 * @param {(string | ContactInterface | FileBox | UrlLinkInterface | MiniProgramInterface | LocationInterface)} textOrContactOrFile
 * 发送文本,联系人,或文件给机器人。
 * @param {(ContactInterface|ContactInterface[])} [mention]
 * 如果这是一个房间消息,当你设置mention参数时,你可以在房间中`@`联系人。
 * @returns {Promise<void | MessageInterface>}
 */
async say (
  textOrContactOrFile : Sayable,
  mention?            : ContactInterface | ContactInterface[],
): Promise<void | MessageInterface> {
  log.verbose('Message', 'say(%s, %s)', textOrContactOrFile, mention)

  const sayable = messageToSayable(textOrContactOrFile)

  let mentionIdList: string[] = []
  if (mention) {
    mentionIdList = Array.isArray(mention)
      ? mention.map(c => c.id)
      : [mention.id]
  }

  const receiver = this.room() || this.talker()
  if (!receiver) {
    throw new Error('no receiver')
  }

  const receiverId = receiver.id

  const messageId = await this.wechaty.puppet.messageSend(
    receiverId,
    sayable,
    mentionIdList,
  )

  if (typeof messageId === 'string') {
    return this.wechaty.Message.load(messageId)
  }

  return
}

在这段代码中,如果提供了mention参数,它会被转换为一个联系人ID的数组(mentionIdList)。然后,这些ID被传递给puppet的messageSend方法,该方法处理实际的消息发送。puppet负责格式化消息,以在正确的位置包含@提及。

参考源码:

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

from wechaty.

wushd avatar wushd commented on June 10, 2024

有没有示例代码能参考一下

from wechaty.

wushd avatar wushd commented on June 10, 2024

如果我想实现@多个人要怎么实现呢,例:你好@A@B@C

from wechaty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.