Skip to content

Commit

Permalink
feat: check values sendText - ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Mar 14, 2021
1 parent 319230f commit dd3eb0c
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit dd3eb0c

Please sign in to comment.