Skip to content

Commit

Permalink
feat: Added newsletter functions (#1893)
Browse files Browse the repository at this point in the history
* feat: Added createNewsletter functions

* fix: Fixed Version Default wajs 2.27.0

* feat: Added createNewsletter functions

* fix: Fixed create newsletter functions and added more function

---------

Co-authored-by: marcelo-megaonline <81028641+marcelo-megaonline@users.noreply.github.com>
Co-authored-by: Cleiton Carvalho <cleitoncosta83@gmail.com>
  • Loading branch information
3 people committed Nov 15, 2023
1 parent 17db4d8 commit 64ed54a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 6 deletions.
6 changes: 2 additions & 4 deletions examples/basic/index.js
Expand Up @@ -28,12 +28,10 @@ function start(client) {
if (message.body === 'Hi' && message.isGroupMsg === false) {
client
.sendText(message.from, 'Welcome Wppconnect')
.then((result) => {
console.log('Result: ', result); //return object success
})
.then((result) => {})
.catch((erro) => {
console.error('Error when sending: ', erro); //return object error
});
}
});
}
}
4 changes: 4 additions & 0 deletions examples/newsletter/.gitignore
@@ -0,0 +1,4 @@
node_modules
tokens
package-lock.json
debug.log
13 changes: 13 additions & 0 deletions examples/newsletter/README.md
@@ -0,0 +1,13 @@
# Simple example to use functions of newsletter

> 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.
42 changes: 42 additions & 0 deletions examples/newsletter/index.js
@@ -0,0 +1,42 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
const wppconnect = require('../../dist');

wppconnect
.create({
session: 'teste',
})
.then((client) => start(client))
.catch((erro) => {
console.log(erro);
});

function start(client) {
client.onMessage(async (message) => {
if (message.body === 'create newsletter' && message.isGroupMsg === false) {
const t = await client.createNewsletter('WPP Test Newsletter2', {
description: 'test',
});
console.log(t);
await client.sendText(message.from, '```' + JSON.stringify(t) + '```');
await client.sendText(
message.from,
'Check the channels of connected device'
);
}
});
}
11 changes: 11 additions & 0 deletions examples/newsletter/package.json
@@ -0,0 +1,11 @@
{
"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"
}
4 changes: 2 additions & 2 deletions src/api/layers/community.layer.ts
Expand Up @@ -19,9 +19,9 @@ import { Page } from 'puppeteer';
import { CreateConfig } from '../../config/create-config';
import { evaluateAndReturn } from '../helpers';
import { Wid } from '../model';
import { HostLayer } from './host.layer';
import { NewsletterLayer } from './newsletter.layer';

export class CommunityLayer extends HostLayer {
export class CommunityLayer extends NewsletterLayer {
constructor(public page: Page, session?: string, options?: CreateConfig) {
super(page, session, options);
}
Expand Down
112 changes: 112 additions & 0 deletions src/api/layers/newsletter.layer.ts
@@ -0,0 +1,112 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

import { Page } from 'puppeteer';
import { CreateConfig } from '../../config/create-config';
import { evaluateAndReturn } from '../helpers';
import { HostLayer } from './host.layer';

export class NewsletterLayer extends HostLayer {
constructor(public page: Page, session?: string, options?: CreateConfig) {
super(page, session, options);
}

/**
* Create Newsletter
* @category Newsletter
*
* @example
* ```javascript
* client.createNewsletter('Name for your newsletter', {description: 'Description for that', picture: '<base64_string',});
* ```
* @param name Name Newsletter
* @param options options Newsletter, description and picture
*/

public async createNewsletter(
name: string,
options?: {
description?: string;
picture?: string;
}
) {
return evaluateAndReturn(
this.page,
(name, options) => WPP.newsletter.create(name, options),
name,
options
);
}

/**
* Destroy a Newsletter
* @category Newsletter
*
* @example
* ```javascript
* client.destroyNewsletter('[newsletter-id]@newsletter');
* ```
* @param name id of Newsletter
*/
public async destroyNewsletter(id: string) {
return evaluateAndReturn(this.page, (id) => WPP.newsletter.destroy(id), id);
}

/**
* Edit a Newsletter
* @category Newsletter
*
* @example
* ```javascript
* client.editNewsletter('[newsletter-id]@newsletter', {
description: 'new description';
name: 'new name';
picture: '<new pic base64>';
});
* ```
* @param name id of Newsletter
*/
public async editNewsletter(
id: string,
opts?: {
description?: string;
name?: string;
picture?: string | null;
}
) {
return evaluateAndReturn(
this.page,
(id, opts) => WPP.newsletter.edit(id, opts),
id,
opts
);
}

/**
* Mute a Newsletter
* @category Newsletter
*
* @example
* ```javascript
* client.muteNewsletter('[newsletter-id]@newsletter');
* ```
* @param name id of Newsletter
*/
public async muteNesletter(id: string) {
return evaluateAndReturn(this.page, (id) => WPP.newsletter.mute(id), id);
}
}

0 comments on commit 64ed54a

Please sign in to comment.