Skip to content

Commit

Permalink
Revert "Orders"
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored Nov 15, 2023
1 parent cdfcbee commit d2eafde
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 192 deletions.
4 changes: 1 addition & 3 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 0 additions & 4 deletions examples/orders/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions examples/orders/README.md

This file was deleted.

51 changes: 0 additions & 51 deletions examples/orders/index.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/orders/package.json

This file was deleted.

33 changes: 0 additions & 33 deletions src/api/layers/listener.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,7 +88,6 @@ export class ListenerLayer extends ProfileLayer {
'onReactionMessage',
'onPollResponse',
'onUpdateLabel',
'onOrderStatusUpdate',
];

for (const func of functions) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
}
}
14 changes: 0 additions & 14 deletions src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<orderId>');
* ```
* @category Order
* @return Your order
*/
public async getOrder(msgId: string) {
return evaluateAndReturn(this.page, (msgId) => WPP.order.get(msgId), msgId);
}
}
63 changes: 0 additions & 63 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(<message>))` 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;
}
}

0 comments on commit d2eafde

Please sign in to comment.