How to use the wechaty-puppet.MessageType.Recalled function in wechaty-puppet

To help you get started, we’ve selected a few wechaty-puppet 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 wechaty / wechaty-puppet-padplus / src / pure-function-helpers / message-type.ts View on Github external
case PadplusMessageType.Video:
      type = MessageType.Video
      // console.log(rawPayload)
      break

    case PadplusMessageType.Sys:
      type = MessageType.Unknown
      break

    case PadplusMessageType.ShareCard:
      type = MessageType.Contact
      break

    case PadplusMessageType.VoipMsg:
    case PadplusMessageType.Recalled:
      type = MessageType.Recalled
      break

    case PadplusMessageType.StatusNotify:
    case PadplusMessageType.SysNotice:
      type = MessageType.Unknown
      break

    default:
      throw new Error('unsupported type: ' + PadplusMessageType[rawType] + '(' + rawType + ')')
  }

  return type
}
github wechaty / wechaty-puppet-padplus / src / pure-function-helpers / message-raw-payload-parser.ts View on Github external
*
   * 4. Set Text
   */
  if (isRoomId(rawPayload.fromUserName)) {

    const startIndex = rawPayload.content.indexOf(':\n')

    text = rawPayload.content.slice(startIndex !== -1 ? startIndex + 2 : 0)

  } else {

    text = rawPayload.content

  }

  if (type === MessageType.Recalled) {

    const recalledPayload = await recalledPayloadParser(rawPayload)
    const pattern = [
      /"(.+)" 撤回了一条消息/,
      /"(.+)" has recalled a message./,
    ]
    const patternSelf = [
      /你撤回了一条消息/,
      /You recalled a message/,
    ]
    if (recalledPayload) {
      const isRecalled = pattern.some(regex => regex.test(recalledPayload.replaceMsg))
      const isRecalledSelf = patternSelf.some(regex => regex.test(recalledPayload.replaceMsg))
      if (isRecalled || isRecalledSelf) {
        text = recalledPayload.newMsgId
        if (isRecalledSelf) {
github wechaty / wechaty / src / user / message.spec.ts View on Github external
sandbox.stub(puppet, 'messagePayload').callsFake(async (id) => {
    await new Promise(resolve => setImmediate(resolve))
    if (id === EXPECTED_RECALL_MESSAGE_ID) {
      return {
        id: EXPECTED_RECALL_MESSAGE_ID,
        text: EXPECTED_RECALLED_MESSAGE_ID,
        timestamp: EXPECTED_MESSAGE_TIMESTAMP,
        type: MessageType.Recalled,
      } as MessagePayload
    } else {
      return {
        fromId: EXPECTED_FROM_CONTACT_ID,
        id: EXPECTED_RECALLED_MESSAGE_ID,
        roomId: EXPECTED_ROOM_ID,
        text: '',
        timestamp: EXPECTED_MESSAGE_TIMESTAMP,
        toId: EXPECTED_TO_CONTACT_ID,
        type: MessageType.Text,
      } as MessagePayload
    }
  })
  sandbox.stub(puppet, 'roomPayload').callsFake(async () => {