mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix(fix/buttons-deprecation): initial/final commit (#956)
This commit is contained in:
@@ -8,7 +8,6 @@ import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, de
|
||||
import { getUrlInfo } from '../Utils/link-preview'
|
||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
||||
import { makeGroupsSocket } from './groups'
|
||||
import ListType = proto.Message.ListMessage.ListType;
|
||||
|
||||
export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const {
|
||||
@@ -306,7 +305,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const relayMessage = async(
|
||||
jid: string,
|
||||
message: proto.IMessage,
|
||||
{ messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions
|
||||
{ messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions
|
||||
) => {
|
||||
const meId = authState.creds.me!.id
|
||||
|
||||
@@ -519,20 +518,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
logger.debug({ jid }, 'adding device identity')
|
||||
}
|
||||
|
||||
const buttonType = getButtonType(message)
|
||||
if(buttonType) {
|
||||
(stanza.content as BinaryNode[]).push({
|
||||
tag: 'biz',
|
||||
attrs: { },
|
||||
content: [
|
||||
{
|
||||
tag: buttonType,
|
||||
attrs: getButtonArgs(message),
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
logger.debug({ jid }, 'adding business node')
|
||||
if(additionalNodes && additionalNodes.length > 0) {
|
||||
(stanza.content as BinaryNode[]).push(...additionalNodes)
|
||||
}
|
||||
|
||||
logger.debug({ msgId }, `sending message to ${participants.length} devices`)
|
||||
@@ -576,36 +563,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getButtonType = (message: proto.IMessage) => {
|
||||
if(message.buttonsMessage) {
|
||||
return 'buttons'
|
||||
} else if(message.buttonsResponseMessage) {
|
||||
return 'buttons_response'
|
||||
} else if(message.interactiveResponseMessage) {
|
||||
return 'interactive_response'
|
||||
} else if(message.listMessage) {
|
||||
return 'list'
|
||||
} else if(message.listResponseMessage) {
|
||||
return 'list_response'
|
||||
}
|
||||
}
|
||||
|
||||
const getButtonArgs = (message: proto.IMessage): BinaryNode['attrs'] => {
|
||||
if(message.templateMessage) {
|
||||
// TODO: Add attributes
|
||||
return {}
|
||||
} else if(message.listMessage) {
|
||||
const type = message.listMessage.listType
|
||||
if(!type) {
|
||||
throw new Boom('Expected list type inside message')
|
||||
}
|
||||
|
||||
return { v: '2', type: ListType[type].toLowerCase() }
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
const getPrivacyTokens = async(jids: string[]) => {
|
||||
const t = unixTimestampSeconds().toString()
|
||||
const result = await query({
|
||||
@@ -647,7 +604,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
relayMessage,
|
||||
sendReceipt,
|
||||
sendReceipts,
|
||||
getButtonArgs,
|
||||
readMessages,
|
||||
refreshMediaConn,
|
||||
waUploadToServer,
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { Readable } from 'stream'
|
||||
import type { URL } from 'url'
|
||||
import { proto } from '../../WAProto'
|
||||
import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults'
|
||||
import { BinaryNode } from '../WABinary'
|
||||
import type { GroupMetadata } from './GroupMetadata'
|
||||
import { CacheStore } from './Socket'
|
||||
|
||||
@@ -60,29 +61,9 @@ type ViewOnce = {
|
||||
viewOnce?: boolean
|
||||
}
|
||||
|
||||
type Buttonable = {
|
||||
/** add buttons to the message */
|
||||
buttons?: proto.Message.ButtonsMessage.IButton[]
|
||||
}
|
||||
type Templatable = {
|
||||
/** add buttons to the message (conflicts with normal buttons)*/
|
||||
templateButtons?: proto.IHydratedTemplateButton[]
|
||||
|
||||
footer?: string
|
||||
}
|
||||
type Editable = {
|
||||
edit?: WAMessageKey
|
||||
}
|
||||
type Listable = {
|
||||
/** Sections of the List */
|
||||
sections?: proto.Message.ListMessage.ISection[]
|
||||
|
||||
/** Title of a List Message only */
|
||||
title?: string
|
||||
|
||||
/** Text of the bnutton on the list (required) */
|
||||
buttonText?: string
|
||||
}
|
||||
type WithDimensions = {
|
||||
width?: number
|
||||
height?: number
|
||||
@@ -111,7 +92,7 @@ export type AnyMediaMessageContent = (
|
||||
image: WAMediaUpload
|
||||
caption?: string
|
||||
jpegThumbnail?: string
|
||||
} & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
|
||||
} & Mentionable & Contextable & WithDimensions)
|
||||
| ({
|
||||
video: WAMediaUpload
|
||||
caption?: string
|
||||
@@ -119,7 +100,7 @@ export type AnyMediaMessageContent = (
|
||||
jpegThumbnail?: string
|
||||
/** if set to true, will send as a `video note` */
|
||||
ptv?: boolean
|
||||
} & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
|
||||
} & Mentionable & Contextable & WithDimensions)
|
||||
| {
|
||||
audio: WAMediaUpload
|
||||
/** if set to true, will send as a `voice note` */
|
||||
@@ -135,7 +116,7 @@ export type AnyMediaMessageContent = (
|
||||
mimetype: string
|
||||
fileName?: string
|
||||
caption?: string
|
||||
} & Contextable & Buttonable & Templatable))
|
||||
} & Contextable))
|
||||
& { mimetype?: string } & Editable
|
||||
|
||||
export type ButtonReplyInfo = {
|
||||
@@ -153,11 +134,11 @@ export type AnyRegularMessageContent = (
|
||||
text: string
|
||||
linkPreview?: WAUrlInfo | null
|
||||
}
|
||||
& Mentionable & Contextable & Buttonable & Templatable & Listable & Editable)
|
||||
& Mentionable & Contextable & Editable)
|
||||
| AnyMediaMessageContent
|
||||
| ({
|
||||
poll: PollMessageOptions
|
||||
} & Mentionable & Contextable & Buttonable & Templatable & Editable)
|
||||
} & Mentionable & Contextable & Editable)
|
||||
| {
|
||||
contacts: {
|
||||
displayName?: string
|
||||
@@ -207,6 +188,7 @@ export type MessageRelayOptions = MinimalRelayOptions & {
|
||||
participant?: { jid: string, count: number }
|
||||
/** additional attributes to add to the WA binary node */
|
||||
additionalAttributes?: { [_: string]: string }
|
||||
additionalNodes?: BinaryNode[]
|
||||
/** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
|
||||
useUserDevicesCache?: boolean
|
||||
/** jid list of participants for status@broadcast */
|
||||
|
||||
@@ -62,8 +62,6 @@ const MessageTypeProto = {
|
||||
'document': WAProto.Message.DocumentMessage,
|
||||
} as const
|
||||
|
||||
const ButtonType = proto.Message.ButtonsMessage.HeaderType
|
||||
|
||||
/**
|
||||
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
||||
* @param text eg. hello https://google.com
|
||||
@@ -487,70 +485,6 @@ export const generateWAMessageContent = async(
|
||||
)
|
||||
}
|
||||
|
||||
if('buttons' in message && !!message.buttons) {
|
||||
const buttonsMessage: proto.Message.IButtonsMessage = {
|
||||
buttons: message.buttons!.map(b => ({ ...b, type: proto.Message.ButtonsMessage.Button.Type.RESPONSE }))
|
||||
}
|
||||
if('text' in message) {
|
||||
buttonsMessage.contentText = message.text
|
||||
buttonsMessage.headerType = ButtonType.EMPTY
|
||||
} else {
|
||||
if('caption' in message) {
|
||||
buttonsMessage.contentText = message.caption
|
||||
}
|
||||
|
||||
const type = Object.keys(m)[0].replace('Message', '').toUpperCase()
|
||||
buttonsMessage.headerType = ButtonType[type]
|
||||
|
||||
Object.assign(buttonsMessage, m)
|
||||
}
|
||||
|
||||
if('footer' in message && !!message.footer) {
|
||||
buttonsMessage.footerText = message.footer
|
||||
}
|
||||
|
||||
m = { buttonsMessage }
|
||||
} else if('templateButtons' in message && !!message.templateButtons) {
|
||||
const msg: proto.Message.TemplateMessage.IHydratedFourRowTemplate = {
|
||||
hydratedButtons: message.templateButtons
|
||||
}
|
||||
|
||||
if('text' in message) {
|
||||
msg.hydratedContentText = message.text
|
||||
} else {
|
||||
|
||||
if('caption' in message) {
|
||||
msg.hydratedContentText = message.caption
|
||||
}
|
||||
|
||||
Object.assign(msg, m)
|
||||
}
|
||||
|
||||
if('footer' in message && !!message.footer) {
|
||||
msg.hydratedFooterText = message.footer
|
||||
}
|
||||
|
||||
m = {
|
||||
templateMessage: {
|
||||
fourRowTemplate: msg,
|
||||
hydratedTemplate: msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if('sections' in message && !!message.sections) {
|
||||
const listMessage: proto.Message.IListMessage = {
|
||||
sections: message.sections,
|
||||
buttonText: message.buttonText,
|
||||
title: message.title,
|
||||
footerText: message.footer,
|
||||
description: message.text,
|
||||
listType: proto.Message.ListMessage.ListType.SINGLE_SELECT
|
||||
}
|
||||
|
||||
m = { listMessage }
|
||||
}
|
||||
|
||||
if('viewOnce' in message && !!message.viewOnce) {
|
||||
m = { viewOnceMessage: { message: m } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user