mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add nextPageCursor
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ProductCreate, ProductUpdate, SocketConfig } from '../Types'
|
import { CatalogCursor, ProductCreate, ProductUpdate, SocketConfig } from '../Types'
|
||||||
import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business'
|
import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business'
|
||||||
import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary'
|
import { BinaryNode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary'
|
||||||
import { getBinaryNodeChild } from '../WABinary/generic-utils'
|
import { getBinaryNodeChild } from '../WABinary/generic-utils'
|
||||||
import { makeMessagesRecvSocket } from './messages-recv'
|
import { makeMessagesRecvSocket } from './messages-recv'
|
||||||
|
|
||||||
@@ -12,9 +12,40 @@ export const makeBusinessSocket = (config: SocketConfig) => {
|
|||||||
waUploadToServer
|
waUploadToServer
|
||||||
} = sock
|
} = sock
|
||||||
|
|
||||||
const getCatalog = async(jid?: string, limit = 10) => {
|
const getCatalog = async(
|
||||||
|
jid?: string,
|
||||||
|
limit = 10,
|
||||||
|
cursor?: CatalogCursor
|
||||||
|
) => {
|
||||||
jid = jid || authState.creds.me?.id
|
jid = jid || authState.creds.me?.id
|
||||||
jid = jidNormalizedUser(jid!)
|
jid = jidNormalizedUser(jid!)
|
||||||
|
|
||||||
|
const queryParamNodes: BinaryNode[] = [
|
||||||
|
{
|
||||||
|
tag: 'limit',
|
||||||
|
attrs: { },
|
||||||
|
content: Buffer.from(limit.toString())
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'width',
|
||||||
|
attrs: { },
|
||||||
|
content: Buffer.from('100')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'height',
|
||||||
|
attrs: { },
|
||||||
|
content: Buffer.from('100')
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
if(cursor) {
|
||||||
|
queryParamNodes.push({
|
||||||
|
tag: 'after',
|
||||||
|
attrs: { },
|
||||||
|
content: cursor
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const result = await query({
|
const result = await query({
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -29,23 +60,7 @@ export const makeBusinessSocket = (config: SocketConfig) => {
|
|||||||
jid,
|
jid,
|
||||||
allow_shop_source: 'true'
|
allow_shop_source: 'true'
|
||||||
},
|
},
|
||||||
content: [
|
content: queryParamNodes
|
||||||
{
|
|
||||||
tag: 'limit',
|
|
||||||
attrs: { },
|
|
||||||
content: Buffer.from(limit.toString())
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'width',
|
|
||||||
attrs: { },
|
|
||||||
content: Buffer.from('100')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'height',
|
|
||||||
attrs: { },
|
|
||||||
content: Buffer.from('100')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,4 +70,6 @@ export type OrderProduct = {
|
|||||||
export type OrderDetails = {
|
export type OrderDetails = {
|
||||||
price: OrderPrice
|
price: OrderPrice
|
||||||
products: OrderProduct[]
|
products: OrderProduct[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CatalogCursor = string
|
||||||
@@ -7,7 +7,14 @@ import { getStream, getUrlFromDirectPath, toReadable } from './messages-media'
|
|||||||
export const parseCatalogNode = (node: BinaryNode) => {
|
export const parseCatalogNode = (node: BinaryNode) => {
|
||||||
const catalogNode = getBinaryNodeChild(node, 'product_catalog')
|
const catalogNode = getBinaryNodeChild(node, 'product_catalog')
|
||||||
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
|
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
|
||||||
return { products }
|
const paging = getBinaryNodeChild(catalogNode, 'paging')
|
||||||
|
|
||||||
|
return {
|
||||||
|
products,
|
||||||
|
nextPageCursor: paging
|
||||||
|
? getBinaryNodeChildString(paging, 'after')
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseCollectionsNode = (node: BinaryNode) => {
|
export const parseCollectionsNode = (node: BinaryNode) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user