Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: newsletter support #820

Closed
wants to merge 6 commits into from
Closed

Conversation

zennn08
Copy link
Contributor

@zennn08 zennn08 commented May 26, 2024

Summary:

Add support for newsletter

Changes:

  • Add method getNewsletterInfo()
  • Add method createNewsLetter()
  • Add method getSubscribedNewsletters()
  • Add method toggleMuteNewsletter()
  • Add method followNewsletter()
  • Add method unFollowNewsletter()
  • Add method updateNewsletterName()
  • Add method updateNewsletterDesc()
  • Add method updateNewsletterPicture()
  • Add method updateNewsletterReactionSetting()
  • Add method removeNewsletterPicture()
  • Support to received newsletter message
  • Support to send newsletter message (text, image, video, ptt, sticker, edit, delete)
  • Add newsletter in MediaGenerationOptions

Note:

To send media to the newsletter, we have to upload the media to the WhatsApp server without encrypting it first.
Newsletter media works mostly the same way as normal media, with a few differences:

  • Since it's unencrypted, there's no mediaKey or fileEncSha256 fields.
  • There's a handle that needs to be passed in additionalAttributes.

@whiskeysockets-bot
Copy link
Contributor

Thanks for your contribution.

The next step is to wait for review and approval to merge it to main repository

The community can help reacting with a thumb up (:thumbsup:) for approval and rocket (:rocket:) for who has tested it.

To test this PR you can run the following command below:

# NPM
npm install @whiskeysockets/baileys@zennn08/Baileys#master
# YARN v2
yarn add @whiskeysockets/baileys@zennn08/Baileys#master

@mzayn
Copy link

mzayn commented May 26, 2024

any for function to send message, link preview, message and other ?

cause i see only to manage channel only in this code

@zennn08
Copy link
Contributor Author

zennn08 commented May 26, 2024

any for function to send message, link preview, message and other ?

cause i see only to manage channel only in this code

Just sendMessage normally with newsletter id

sock.sendMessage("13731837@newsletter", { text: "Hello" })

@mzayn
Copy link

mzayn commented May 26, 2024

any for function to send message, link preview, message and other ?
cause i see only to manage channel only in this code

Just sendMessage normally with newsletter id

sock.sendMessage("13731837@newsletter", { text: "Hello" })

for this i was success send as plain text,
but fail to link preview message, media message, and file message.

@vinikjkkj
Copy link
Contributor

I didn't see that you also did a PR on this

@zennn08
Copy link
Contributor Author

zennn08 commented May 26, 2024

any for function to send message, link preview, message and other ?
cause i see only to manage channel only in this code

Just sendMessage normally with newsletter id

sock.sendMessage("13731837@newsletter", { text: "Hello" })

for this i was success send as plain text, but fail to link preview message, media message, and file message.

how do you send other the message? does it use the sendMessage function?

@ernestoyoofi
Copy link

any for function to send message, link preview, message and other ?
cause i see only to manage channel only in this code

Just sendMessage normally with newsletter id

sock.sendMessage("13731837@newsletter", { text: "Hello" })

for this i was success send as plain text, but fail to link preview message, media message, and file message.

How to send files into channel?, it's not that whatsapp currently can't send files into channels, it can only send media such as voice, video and image, other than that it's just a poll, is it possible?

@cifumo
Copy link

cifumo commented May 26, 2024

error in followNewsletter(id)
error:[{"message":"Bad Request","path":["xwa2_newsletter_join_v2"],"extensions":{"error_code":400,"severity":"CRITICAL","is_retryable":false}}]

@Yuri-Neko
Copy link

Yuri-Neko commented May 31, 2024

Summary:

Add support for newsletter

Changes:

  • Add method getNewsletterInfo()
  • Add method createNewsLetter()
  • Add method getSubscribedNewsletters()
  • Add method toggleMuteNewsletter()
  • Add method followNewsletter()
  • Add method unFollowNewsletter()
  • Support to received newsletter message
  • Support to send newsletter message (text, image, video, ptt, sticker, edit, delete)
  • Add newsletter in MediaGenerationOptions

Note:

To send media to the newsletter, we have to upload the media to the WhatsApp server without encrypting it first. Newsletter media works mostly the same way as normal media, with a few differences:

  • Since it's unencrypted, there's no mediaKey or fileEncSha256 fields.
  • There's a handle that needs to be passed in additionalAttributes.

Cannot send media {documents, audio, video, photos, vn,sticker [only text]) using the sendFile function to the Group

what's wrong, but when using a baileys npm:@whiskeysocket/baileys@latest it works
The downside is that you can't send to channel

(conn.sendFile = async (
      jid,
      path,
      filename = "",
      caption = "",
      quoted,
      ptt = false,
      options = {},
    ) => {
      let type = await conn.getFile(path, true);
      let { res, data: file, filename: pathFile } = type;
      if ((res && res.status !== 200) || file.length <= 65536) {
        try {
          throw { json: JSON.parse(file.toString()) };
        } catch (e) {
          if (e.json) throw e.json;
        }
      }
      let opt = { filename };
      if (quoted) opt.quoted = quoted;
      if (!type) options.asDocument = true;
      let mtype = "",
        mimetype = type.mime,
        convert;
      if (
        /webp/.test(type.mime) ||
        (/image/.test(type.mime) && options.asSticker)
      )
        mtype = "sticker";
      else if (
        /image/.test(type.mime) ||
        (/webp/.test(type.mime) && options.asImage)
      )
        mtype = "image";
      else if (/video/.test(type.mime)) mtype = "video";
      else if (/audio/.test(type.mime))
        (convert = await (ptt ? toPTT : toAudio)(file, type.ext)),
          (file = convert.data),
          (pathFile = convert.filename),
          (mtype = "audio"),
          (mimetype = "audio/mpeg");
      else mtype = "document";
      if (options.asDocument) mtype = "document";

      let message = {
        ...options,
        caption,
        ptt,
        [mtype]: { url: pathFile },
        mimetype,
      };
      let m;
      try {
        m = await conn.sendMessage(jid, message, { ...opt, ...options });
      } catch (e) {
        console.error(e);
        m = null;
      } finally {
        if (!m)
          m = await conn.sendMessage(
            jid,
            { ...message, [mtype]: file },
            { ...opt, ...options },
          );
        return m;
      }
    });

@zennn08 zennn08 requested a review from nstar-y June 2, 2024 02:08
@manojsitapara
Copy link

manojsitapara commented Jun 2, 2024

any for function to send message, link preview, message and other ?
cause i see only to manage channel only in this code

Just sendMessage normally with newsletter id

sock.sendMessage("13731837@newsletter", { text: "Hello" })

@zennn08 I am able to send message on newsletter but messages can be seen only in web.whatsapp.com but not on mobile WhatsApp

anything am I doing wrong?

Web version output

image

Mobile version output

image

@joweste
Copy link

joweste commented Jul 22, 2024

How can I list all newsletters? I just created one but I don’t know how I get your metadata.
I tried the next and I get a empty array:
const nn = await getSubscribedNewsletters();
console.log("nn", nn);

@PurpShell PurpShell marked this pull request as draft July 27, 2024 14:56
@ernestoyoofi
Copy link

IMG-20240804-WA0745

on updates on the WhatsApp update, i found this part, is this part of the profile picture of the channel?

@PurpShell PurpShell closed this Sep 22, 2024
@ninjaarara
Copy link

how to make it like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.