Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added newsletter functions (#1893)
* 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
1 parent
17db4d8
commit 64ed54a
Showing
7 changed files
with
186 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
tokens | ||
package-lock.json | ||
debug.log |
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 |
---|---|---|
@@ -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. |
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 |
---|---|---|
@@ -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' | ||
); | ||
} | ||
}); | ||
} |
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 |
---|---|---|
@@ -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" | ||
} |
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |