-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
22 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 |
---|---|---|
|
@@ -71,7 +71,7 @@ import { | |
} from '../model'; | ||
import { ChatState } from '../model/enum'; | ||
import { ListenerLayer } from './listener.layer'; | ||
import { Scope } from './layers-interface'; | ||
import { Scope, checkValuesSender } from '../helpers/layers-interface'; | ||
|
||
let obj: Scope; | ||
|
||
|
@@ -81,43 +81,62 @@ export class SenderLayer extends ListenerLayer { | |
} | ||
|
||
/** | ||
* Automatically sends a link with the auto generated link preview. You can also add a custom message to be added. | ||
* @param chatId | ||
* @param url string A link, for example for youtube. e.g https://www.youtube.com/watch?v=Zi_XLOBDo_Y&list=RDEMe12_MlgO8mGFdeeftZ2nOQ&start_radio=1 | ||
* @param title custom text as the message body, this includes the link or will be attached after the link | ||
* Sends a text message to given chat | ||
* @param to chat id: [email protected] or | ||
* @param content text message | ||
*/ | ||
public async sendLinkPreview( | ||
chatId: string, | ||
url: string, | ||
title: string | ||
): Promise<SendLinkResult> { | ||
public async sendText(to: string, content: string): Promise<Object> { | ||
return new Promise(async (resolve, reject) => { | ||
const typeFunction = 'sendText'; | ||
const check = [ | ||
{ | ||
param: 'to', | ||
type: 'string', | ||
value: to, | ||
function: typeFunction, | ||
}, | ||
{ | ||
param: 'content', | ||
type: 'string', | ||
value: content, | ||
function: typeFunction, | ||
}, | ||
]; | ||
const validating = checkValuesSender(check); | ||
if (typeof validating === 'object') { | ||
return reject(validating); | ||
} | ||
const result = await this.page.evaluate( | ||
({ chatId, url, title }) => { | ||
return WAPI.sendLinkPreview(chatId, url, title); | ||
({ to, content }) => { | ||
return WAPI.sendMessage(to, content); | ||
}, | ||
{ chatId, url, title } | ||
{ to, content } | ||
); | ||
if (result['erro'] == true) { | ||
reject(result); | ||
return reject(result); | ||
} else { | ||
resolve(result); | ||
return resolve(result); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Sends a text message to given chat | ||
* @param to chat id: [email protected] | ||
* @param content text message | ||
* Automatically sends a link with the auto generated link preview. You can also add a custom message to be added. | ||
* @param chatId | ||
* @param url string A link, for example for youtube. e.g https://www.youtube.com/watch?v=Zi_XLOBDo_Y&list=RDEMe12_MlgO8mGFdeeftZ2nOQ&start_radio=1 | ||
* @param title custom text as the message body, this includes the link or will be attached after the link | ||
*/ | ||
public async sendText(to: string, content: string) { | ||
public async sendLinkPreview( | ||
chatId: string, | ||
url: string, | ||
title: string | ||
): Promise<SendLinkResult> { | ||
return new Promise(async (resolve, reject) => { | ||
const result = await this.page.evaluate( | ||
({ to, content }) => { | ||
return WAPI.sendMessage(to, content); | ||
({ chatId, url, title }) => { | ||
return WAPI.sendLinkPreview(chatId, url, title); | ||
}, | ||
{ to, content } | ||
{ chatId, url, title } | ||
); | ||
if (result['erro'] == true) { | ||
reject(result); | ||
|