forked from danielcardeenas/sulla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
business.layer.ts
55 lines (51 loc) Β· 1.38 KB
/
business.layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Page } from 'puppeteer';
import { ControlsLayer } from './controls.layer';
declare module WAPI {
const getBusinessProfilesProducts: (to: string) => any;
const sendImageWithProduct: (
base64: string,
to: string,
caption: string,
bizNumber: string,
productId: string
) => any;
}
export class BusinessLayer extends ControlsLayer {
constructor(page: Page) {
super(page);
}
/**
* Querys product catalog
* @param id Buisness profile id ('[email protected]')
*/
public async getBusinessProfilesProducts(id: string) {
return this.page.evaluate(
({ id }) => {
WAPI.getBusinessProfilesProducts(id);
},
{ id }
);
}
/**
* Sends product with product image to given chat id
* @param to Chat id
* @param base64 Base64 image data
* @param caption Message body
* @param businessId Business id number that owns the product ('[email protected]')
* @param productId Product id, see method getBusinessProfilesProducts for more info
*/
public async sendImageWithProduct(
to: string,
base64: string,
caption: string,
businessId: string,
productId: string
) {
return this.page.evaluate(
({ to, base64, businessId, caption, productId }) => {
WAPI.sendImageWithProduct(base64, to, caption, businessId, productId);
},
{ to, base64, businessId, caption, productId }
);
}
}