Skip to content

Commit

Permalink
feat: Added WPP.catalog.getProductById function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Aug 13, 2022
1 parent f4d1716 commit 0b883a3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/catalog/functions/getProductById.ts
@@ -0,0 +1,41 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { assertGetProduct } from '../../assert';
import { createWid } from '../../util';
import { CatalogStore, ProductModel, UserPrefs } from '../../whatsapp';
import { queryProduct } from '../../whatsapp/functions';

/**
* Retrieves product by id
*
* @example
* ```javascript
* // Retrieve data of product
* await WPP.catalog.getProductById('5521985565656@c.us', '68685985868923');
* ```
*
* @category Catalog
*/

export async function getProductById(
chatId: string,
productId: number
): Promise<ProductModel> {
let wid = createWid(chatId);
const { data } = await queryProduct(wid, productId);
return data;
}

0 comments on commit 0b883a3

Please sign in to comment.