From d2eafdefdeff178c93802c0b1a5f2ac3b89ed9fd Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Wed, 15 Nov 2023 09:24:23 -0300 Subject: [PATCH] Revert "Orders" --- examples/basic/README.md | 4 +- examples/orders/.gitignore | 4 -- examples/orders/README.md | 13 ------- examples/orders/index.js | 51 ------------------------- examples/orders/package.json | 11 ------ src/api/layers/listener.layer.ts | 33 ---------------- src/api/layers/retriever.layer.ts | 14 ------- src/api/layers/sender.layer.ts | 63 ------------------------------- 8 files changed, 1 insertion(+), 192 deletions(-) delete mode 100644 examples/orders/.gitignore delete mode 100644 examples/orders/README.md delete mode 100644 examples/orders/index.js delete mode 100644 examples/orders/package.json diff --git a/examples/basic/README.md b/examples/basic/README.md index a642373a7..1db83d7a5 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -1,6 +1,4 @@ -# Simple example to start the Wppconnect and send a order message - -Is necessary to login with a business account +# Simple example to start the Wppconnect > Wppconnect is a high-performance system developed with JavaScript to create a bot for WhatsApp, support for creating any interaction, such as customer service, media sending, sentence recognition based on artificial intelligence and all types of design architecture for WhatsApp. diff --git a/examples/orders/.gitignore b/examples/orders/.gitignore deleted file mode 100644 index 27826cf8a..000000000 --- a/examples/orders/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -tokens -package-lock.json -debug.log \ No newline at end of file diff --git a/examples/orders/README.md b/examples/orders/README.md deleted file mode 100644 index 1db83d7a5..000000000 --- a/examples/orders/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Simple example to start the Wppconnect - -> Wppconnect is a high-performance system developed with JavaScript to create a bot for WhatsApp, support for creating any interaction, such as customer service, media sending, sentence recognition based on artificial intelligence and all types of design architecture for WhatsApp. - -## Maintainers - -Maintainers are needed, I cannot keep with all the updates by myself. If you are -interested please open a Pull Request. - -## Contributing - -Pull requests are welcome. For major changes, please open an issue first to -discuss what you would like to change. diff --git a/examples/orders/index.js b/examples/orders/index.js deleted file mode 100644 index c5b551930..000000000 --- a/examples/orders/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of WPPConnect. - * - * WPPConnect is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * WPPConnect is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with WPPConnect. If not, see . - */ -const wppconnect = require('../../dist'); - -const froms = []; -wppconnect - .create() - .then((client) => start(client)) - .catch((erro) => { - console.log(erro); - }); - -function start(client) { - client.onMessage(async (message) => { - if (message.body === 'new order' && message.isGroupMsg === false) { - const order = await client.sendOrderMessage(message.from, [ - { type: 'custom', name: 'Item with cost test', price: 120000, qnt: 2 }, - ]); - froms.push(message.from); - client.sendText( - message.from, - `Please, save your order id, and get order for test porpouse` - ); - client.sendText(message.from, `${order.id}`); - } - if (message?.body?.includes('order id=') && message?.isGroupMsg === false) { - const id = message?.body.split('=')[1]; - const order = await client.getOrder(id); - client.sendText(message.from, '```' + JSON.stringify(order) + '```'); - } - }); - client.onOrderStatusUpdate((data) => { - froms.forEach((from) => { - client.sendText(from, '```' + JSON.stringify(data) + '```'); - }); - }); -} diff --git a/examples/orders/package.json b/examples/orders/package.json deleted file mode 100644 index ec7411cb3..000000000 --- a/examples/orders/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "wppconnect-functions", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "start": "node index.js", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "license": "ISC" -} diff --git a/src/api/layers/listener.layer.ts b/src/api/layers/listener.layer.ts index bf661851b..fcca8d9da 100644 --- a/src/api/layers/listener.layer.ts +++ b/src/api/layers/listener.layer.ts @@ -34,7 +34,6 @@ import { InterfaceMode } from '../model/enum/interface-mode'; import { InterfaceState } from '../model/enum/interface-state'; import { ProfileLayer } from './profile.layer'; import { Label } from '../model/label'; -import { MsgKey } from '@wppconnect/wa-js/dist/whatsapp'; declare global { interface Window { @@ -89,7 +88,6 @@ export class ListenerLayer extends ProfileLayer { 'onReactionMessage', 'onPollResponse', 'onUpdateLabel', - 'onOrderStatusUpdate', ]; for (const func of functions) { @@ -289,22 +287,6 @@ export class ListenerLayer extends ProfileLayer { } catch (error) { console.error(error); } - try { - if (!window['onOrderStatusUpdate'].exposed) { - WPP.on('order.payment_status', (data) => { - const eventData = { - method: data.method, - timestamp: data.timestamp, - reference_id: data.reference_id, - msgId: data.msgId, - }; - window['onOrderStatusUpdate'](eventData); - }); - window['onOrderStatusUpdate'].exposed = true; - } - } catch (error) { - console.error(error); - } try { if (!window['onParticipantsChanged'].exposed) { WPP.on('group.participant_changed', (participantChangedEvent) => { @@ -664,19 +646,4 @@ export class ListenerLayer extends ProfileLayer { ) { return this.registerEvent('onUpdateLabel', callback); } - - /** - * @event Listens to update order status - * @returns Disposable object to stop the listening - */ - public onOrderStatusUpdate( - callback: (data: { - method: string; - timestamp: number; - reference_id: string; - msgId: MsgKey; - }) => any - ) { - return this.registerEvent('onOrderStatusUpdate', callback); - } } diff --git a/src/api/layers/retriever.layer.ts b/src/api/layers/retriever.layer.ts index 0fa5e9793..12e9dda7c 100644 --- a/src/api/layers/retriever.layer.ts +++ b/src/api/layers/retriever.layer.ts @@ -580,18 +580,4 @@ export class RetrieverLayer extends SenderLayer { WPP.group.getGroupSizeLimit() ); } - - /** - * Get info of your sended order - * - * @example - * ```javascript - * const orderInfo = await client.getOrder(''); - * ``` - * @category Order - * @return Your order - */ - public async getOrder(msgId: string) { - return evaluateAndReturn(this.page, (msgId) => WPP.order.get(msgId), msgId); - } } diff --git a/src/api/layers/sender.layer.ts b/src/api/layers/sender.layer.ts index c5be83e0c..6fc863cc1 100644 --- a/src/api/layers/sender.layer.ts +++ b/src/api/layers/sender.layer.ts @@ -40,10 +40,6 @@ import { filenameFromMimeType } from '../helpers/filename-from-mimetype'; import { Message, SendFileResult, SendStickerResult } from '../model'; import { ChatState } from '../model/enum'; import { ListenerLayer } from './listener.layer'; -import { - OrderItems, - OrderMessageOptions, -} from '@wppconnect/wa-js/dist/chat/functions/sendOrderMessage'; export class SenderLayer extends ListenerLayer { constructor(public page: Page, session?: string, options?: CreateConfig) { @@ -1340,63 +1336,4 @@ export class SenderLayer extends ListenerLayer { } ); } - - /** - * Send a order message - * To send (prices, tax, shipping or discount), for example: USD 12.90, send them without dots or commas, like: 12900 - * - * @example - * ```javascript - * // Send Order with a product - * client.sendOrderMessage('[number]@c.us', [ - * { type: 'product', id: '67689897878', qnt: 2 }, - * { type: 'product', id: '37878774457', qnt: 1 }, - * ] - * - * // Send Order with a custom item - * client.sendOrderMessage('[number]@c.us', [ - * { type: 'custom', name: 'Item de cost test', price: 120000, qnt: 2 }, - * ] - * - * // Send Order with custom options - * client.sendOrderMessage('[number]@c.us', [ - * { type: 'product', id: '37878774457', qnt: 1 }, - * { type: 'custom', name: 'Item de cost test', price: 120000, qnt: 2 }, - * ], - * { tax: 10000, shipping: 4000, discount: 10000 } - * ``` - * - * @category Chat - */ - public async sendOrderMessage( - to: string, - items: OrderItems[], - options?: OrderMessageOptions - ) { - const sendResult = await evaluateAndReturn( - this.page, - ({ to, items, options }) => WPP.chat.sendOrderMessage(to, items, options), - { - to, - items, - options, - } - ); - - // I don't know why the evaluate is returning undefined for direct call - // To solve that, I added `JSON.parse(JSON.stringify())` to solve that - const result = (await evaluateAndReturn( - this.page, - async ({ messageId }) => { - return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId))); - }, - { messageId: sendResult.id } - )) as Message; - - if (result['erro'] == true) { - throw result; - } - - return result; - } }