How to use the wechaty.Contact.load function in wechaty

To help you get started, we’ve selected a few wechaty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github huan / botbuilder-wechaty-adapter / src / wechaty-connector.ts View on Github external
public async send (
    messageList: builder.IMessage[],
    done: (
      err:        Error,
      addresses?: builder.IAddress[],
    ) => void,
  ): Promise {

    const addresses: any[] = []

    for (let idx = 0; idx < messageList.length; idx++) {
      const msg = messageList[idx]
      try {
        const wechatyContact = Contact.load(msg.address.user.id)
        await wechatyContact.ready()

        if (msg.type === 'delay') {
          await new Promise(r => setTimeout(r, (msg as any).value))
        } else if (msg.type === 'message') {
          if (msg.text) {
            await wechatyContact.say(msg.text)
          }
          if (msg.attachments && msg.attachments.length > 0) {
            // for (const attachment of msg.attachments) {
              // renderAttachment(attachment)
            // }
          }
          addresses.push({
            ...msg.address,
            id: idx,