-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Edgard <[email protected]>
- Loading branch information
1 parent
e7e028e
commit b0bab71
Showing
28 changed files
with
776 additions
and
54 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 |
---|---|---|
|
@@ -86,6 +86,6 @@ | |
"webpack-cli": "^5.1.4" | ||
}, | ||
"engines": { | ||
"whatsapp-web": ">=2.2245.8-beta" | ||
"whatsapp-web": ">=2.2321.6-beta" | ||
} | ||
} |
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
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
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,71 @@ | ||
/*! | ||
* Copyright 2023 WPPConnect Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { blobToBase64, convertToFile, downloadImage } from '../../util'; | ||
import { createNewsletterQuery } from '../../whatsapp/functions'; | ||
|
||
export interface ResultCreateNewsletter { | ||
idJid: string; | ||
inviteCode: string; | ||
inviteLink: string; | ||
name: string; | ||
state: string; | ||
subscribersCount: number; | ||
description: string | null; | ||
timestamp: number; | ||
} | ||
|
||
/** | ||
* Create a newsletter | ||
* | ||
* @example | ||
* ```javascript | ||
* // To edit name | ||
* WPP.newsletter.create('Name for your newsletter', { | ||
* description: 'Description for that', | ||
* picture: '<base64_string', | ||
* }); | ||
* ``` | ||
* @category Newsletter | ||
*/ | ||
export async function create( | ||
name: string, | ||
opts: { description?: string; picture?: string } | ||
): Promise<ResultCreateNewsletter> { | ||
let pic = undefined; | ||
if (opts?.picture) { | ||
const file = await convertToFile(opts.picture); | ||
pic = await blobToBase64(file); | ||
({ data: pic } = await downloadImage(pic, 'image/jpeg')); | ||
} | ||
const result = await createNewsletterQuery({ | ||
name: name, | ||
description: opts?.description || null, | ||
picture: pic || null, | ||
}); | ||
|
||
return { | ||
idJid: result?.idJid, | ||
inviteCode: result?.newsletterInviteLinkMetadataMixin.inviteCode, | ||
inviteLink: `https://whatsapp.com/channel/${result?.newsletterInviteLinkMetadataMixin.inviteCode}`, | ||
name: result?.newsletterNameMetadataMixin?.nameElementValue, | ||
state: result?.newsletterStateMetadataMixin?.stateType, | ||
subscribersCount: | ||
result?.newsletterSubscribersMetadataMixin.subscribersCount, | ||
description: opts?.description || null, | ||
timestamp: result?.newsletterCreationTimeMetadataMixin?.creationTimeValue, | ||
}; | ||
} |
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,41 @@ | ||
/*! | ||
* Copyright 2023 WPPConnect Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { WPPError } from '../../util'; | ||
import { deleteNewsletter } from '../../whatsapp/functions'; | ||
|
||
/** | ||
* Delete a newsletter | ||
* | ||
* @example | ||
* ```javascript | ||
* const code = WPP.newsletter.destroy('[newsletter-id]@newsletter'); | ||
* ``` | ||
* | ||
* @category Newsletter | ||
*/ | ||
export async function destroy(id: string): Promise<boolean> { | ||
if (!id || !id.includes('newsletter')) | ||
throw new WPPError( | ||
'send_correctly_newsletter_id', | ||
'Please, send the correct newsletter ID.' | ||
); | ||
try { | ||
return await deleteNewsletter(id); | ||
} catch (error) { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.