Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added get, create, edit, and delete collections functions (fix #…
…442)
- Loading branch information
1 parent
8e8bb22
commit ef6192b
Showing
10 changed files
with
255 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*! | ||
* Copyright 2022 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 { ProductCatalogSession } from '../../whatsapp'; | ||
import { createCollection as CreateCollection } from '../../whatsapp/functions'; | ||
|
||
/** | ||
* Create new collection | ||
* | ||
* @example | ||
* ```javascript | ||
* const myCatalog = await WPP.catalog.createCollection('Collection Name', ['565656589898']); | ||
* ``` | ||
* | ||
* @return Return collection created | ||
*/ | ||
export async function createCollection( | ||
collectionName: string, | ||
productsId: string[] | ||
): Promise<any> { | ||
const { sessionId } = new ProductCatalogSession(true); | ||
|
||
return await CreateCollection(collectionName, productsId, `${sessionId}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*! | ||
* Copyright 2022 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 { ProductCatalogSession } from '../../whatsapp'; | ||
import { deleteCollection as DeleteCollection } from '../../whatsapp/functions'; | ||
|
||
/** | ||
* Delete a collection | ||
* | ||
* @example | ||
* ```javascript | ||
* const myCatalog = await WPP.catalog.deleteCollection("377095767832354"); | ||
* ``` | ||
* | ||
* @return Return sucess or error | ||
*/ | ||
export async function deleteCollection(collectionId: string): Promise<any> { | ||
const { sessionId } = new ProductCatalogSession(true); | ||
await DeleteCollection(collectionId, `${sessionId}`); | ||
return 'Collection deleted sucessful'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*! | ||
* Copyright 2022 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 { ProductCatalogSession } from '../../whatsapp'; | ||
import { editCollection as EditCollection } from '../../whatsapp/functions'; | ||
|
||
/** | ||
* Create new collection | ||
* | ||
* @example | ||
* ```javascript | ||
* const myCatalog = await WPP.catalog.EditCollection('565656589898', { collectionName: 'New Name for collection', productsToAdd: ['5656523223'], productsToRemove: ['5656523232']}); | ||
* ``` | ||
* | ||
* @return Return collection edited | ||
*/ | ||
interface paramsEditCollection { | ||
name?: string; | ||
productsToAdd?: string[]; | ||
productsToRemove?: string[]; | ||
} | ||
export async function editCollection( | ||
collectionId: string, | ||
params: paramsEditCollection | ||
): Promise<any> { | ||
const { sessionId } = new ProductCatalogSession(true); | ||
|
||
return await EditCollection( | ||
collectionId, | ||
params.name, | ||
false, | ||
params.productsToAdd || [], | ||
params.productsToRemove || [], | ||
`${sessionId}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*! | ||
* 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 { createWid } from '../../util'; | ||
import { ProductCollModel } from '../../whatsapp'; | ||
import { queryCollectionsIQ } from '../../whatsapp/functions'; | ||
|
||
/** | ||
* Get collections of catalog | ||
* | ||
* @example | ||
* ```javascript | ||
* // Retrieve 20 collections of chat | ||
* const myCatalog = await WPP.catalog.getCollections('552198554578@c.us', '20'); | ||
* | ||
* // Retrieve 20 collections of chat and products arrays limit with 10 products | ||
* const myCatalog = await WPP.catalog.getCollections('552198554578@c.us', '20', '10'); | ||
* ``` | ||
* | ||
* @return Your collections of products | ||
*/ | ||
export async function getCollections( | ||
chatId: string, | ||
qnt?: number, | ||
productsCount?: number | ||
): Promise<ProductCollModel[]> { | ||
const { collections } = await queryCollectionsIQ({ | ||
afterCursor: '', | ||
catalogWid: createWid(chatId), | ||
height: 100, | ||
width: 100, | ||
limit: qnt || 10, | ||
productsCount: productsCount || 10, | ||
}); | ||
return collections; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*! | ||
* 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 { exportModule } from '../exportModule'; | ||
import { Wid } from '../misc'; | ||
|
||
/** @whatsapp 409465 | ||
*/ | ||
export declare function createCollection(...args: any[]): Promise<any>; | ||
|
||
/** @whatsapp 409465 | ||
*/ | ||
export declare function deleteCollection( | ||
id: string, | ||
sessionId: string | ||
): Promise<any>; | ||
|
||
/** @whatsapp 409465 | ||
*/ | ||
export declare function editCollection( | ||
collectionId: string, | ||
collectionName: string | undefined, | ||
collectionBoolea: boolean, | ||
productsToAdd: string[], | ||
productsToRemove: string[], | ||
sessionId: string | ||
): Promise<any>; | ||
|
||
export interface QueryCollectionsIQtParams { | ||
afterCursor?: string; | ||
catalogWid?: Wid; | ||
directConnectionEncryptedInfo?: any; | ||
height?: 100; | ||
width?: 100; | ||
limit: number; | ||
productsCount?: number; | ||
} | ||
|
||
export declare function queryCollectionsIQ( | ||
params: QueryCollectionsIQtParams | ||
): any; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
createCollection: 'createCollection', | ||
deleteCollection: 'deleteCollection', | ||
editCollection: 'editCollection', | ||
queryCollectionsIQ: 'queryCollectionsIQ', | ||
}, | ||
(m) => m.createCollection | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters