@juzi/wechaty-puppet-whatsapp
Version:
Wechaty Puppet for WhatsApp
64 lines (60 loc) • 1.82 kB
text/typescript
import type * as PUPPET from '@juzi/wechaty-puppet'
import type { } from '@juzi/whatsapp-web.js'
import type {
GroupNotification,
WhatsAppContactPayload,
} from '../../schema/whatsapp-type.js'
import {
MessageTypes as WhatsAppMessageType,
} from '../../schema/whatsapp-interface.js'
export function genRoomTopicEvent (notification: GroupNotification, roomPayload: WhatsAppContactPayload) {
const roomIdObj = notification.id
const roomId = roomIdObj.remote
const roomTopicPayload: PUPPET.payloads.EventRoomTopic = {
changerId: notification.author,
newTopic: notification.body,
oldTopic: roomPayload.name || '',
roomId,
timestamp: notification.timestamp,
}
return roomTopicPayload
}
export function genRoomJoinEvent (notification: GroupNotification, members: string[]) {
const roomIdObj = notification.id
const roomId = roomIdObj.remote
const roomJoinPayload: PUPPET.payloads.EventRoomJoin = {
inviteeIdList: members,
inviterId: notification.author,
roomId,
timestamp: notification.timestamp,
}
return roomJoinPayload
}
export function genRoomAnnounce (notification: GroupNotification, description: string) {
const roomIdObj = notification.id
const roomId = roomIdObj.remote
const genMessagePayload = {
ack: 2,
author: notification.author,
body: description,
broadcast: false,
forwardingScore: 0,
from: roomIdObj.participant || notification.author,
fromMe: roomIdObj.fromMe,
hasMedia: false,
hasQuotedMsg: false,
id: notification.id,
isEphemeral: false,
isForwarded: false,
isGif: false,
isStarred: false,
isStatus: false,
links: [],
mentionedIds: [],
timestamp: Date.now(),
to: roomId,
type: WhatsAppMessageType.TEXT,
vCards: [],
}
return genMessagePayload
}