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

How do I send a message to a whatsapp channel? #549

Open
ernestoyoofi opened this issue Dec 16, 2023 · 48 comments
Open

How do I send a message to a whatsapp channel? #549

ernestoyoofi opened this issue Dec 16, 2023 · 48 comments
Labels
bug Something isn't working

Comments

@ernestoyoofi
Copy link

Describe the bug
I tried to send a message in channel with baileys, but it didn't work and instead sent to an id with nowhere to go.
Screenshot_2023-12-16-10-51-34-648_com whatsapp
Screenshot_2023-12-16-10-51-21-854_com whatsapp

To Reproduce
Steps to reproduce the behavior:

  1. I tried to find the channel id by logging into whatsapp web using kiwi browser so that I can see the Inspect element, and I found the id 120363190224821113@newsletter as per the screenshot below
    Screenshot_2023-12-16-10-47-35-633_com kiwibrowser browser

  2. I created a trigger function where if I send the command !msgtochannel can send to the channel
    Screenshot_2023-12-16-10-49-27-271_com rhmsoft edit pro

  3. After that I tried to send a command so that the message was sent to the channel, but the result was nothing at all, no error occurred.

    Screenshot_2023-12-16-11-13-16-597_com whatsapp

    I don't know where this is actually going.

    Screenshot_2023-12-16-11-13-25-787_com whatsapp

Expected behavior
I wish I could send messages to my whatsapp channel with baileys like on whatsapp web too.

Environment (please complete the following information):

  • Is this on a server? No, I'm running it on my phone (termux)
  • What do your connectOptions look like?
    {
      auth: state,
      logger: P({ level: "silent" }),
      printQRInTerminal: false,
      syncFullHistory: false,
      generateHighQualityLinkPreview: true,
      version: [2,2323,4],
      browser: ["Chrome (Linux)", "browser", ""],
    }
    Screenshot_2023-12-16-10-59-26-958_com rhmsoft edit pro
  • Do you have multiple clients on the same IP? No
  • Are you using a proxy? No
@ernestoyoofi ernestoyoofi added the bug Something isn't working label Dec 16, 2023
@ernestoyoofi
Copy link
Author

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id

Screenshot_2023-12-16-11-24-45-228_com termux

@zaadevofc
Copy link

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id

Screenshot_2023-12-16-11-24-45-228_com termux

what is the name of the event you use?

@ernestoyoofi
Copy link
Author

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id
Screenshot_2023-12-16-11-24-45-228_com termux

what is the name of the event you use?

messages.upsert but actually no message was sent on the event, then i try to add .then(console.log) to see the structure of the message being sent

@ravindu01manoj
Copy link
Contributor

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id

Screenshot_2023-12-16-11-24-45-228_com termux

the JID replace 'newsletter' with 's.whatsapp.net' in JID normalization function. Channel messages are not end-to-end encrypted, so we cannot send messages to channels using the 'sendMessage' function.

@ernestoyoofi
Copy link
Author

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id
Screenshot_2023-12-16-11-24-45-228_com termux

the JID replace 'newsletter' with 's.whatsapp.net' in JID normalization function. Channel messages are not end-to-end encrypted, so we cannot send messages to channels using the 'sendMessage' function.

So, is there a workaround to send messages to the channel? or, maybe there is another solution to send a message to the channel, i'll wait for the latest update if there is one.

@guimox
Copy link

guimox commented Jan 7, 2024

@Auties00 any updates on this?

@Riders004
Copy link

Find the channel id in console by running the bot

@ernestoyoofi
Copy link
Author

Find the channel id in console by running the bot

I didn't find the channel id at all, how?, in the bot console it's not there either

@mzayn
Copy link

mzayn commented Feb 21, 2024

still have update for this ?
cause want to send message at channel

@himanshuja
Copy link

Do anybody get any workaround on this? Thanks in Advance.

@Raf1nho
Copy link

Raf1nho commented Apr 10, 2024

I did lots of tests and research about this feature and seems like it's not really possible to send messages to channels through baileys right now. I couldn't find any workaround.

I've seem messages from @purpshell on the lib discord server saying they are working on supporting WhatsApp channels.

@Rippanteq7
Copy link

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y
Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

@Rippanteq7
Copy link

Rippanteq7 commented Apr 13, 2024

I've tried it by converting function from Whatsmeow library to Baileys library

@mzayn
Copy link

mzayn commented Apr 13, 2024

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

can your share the sample code for send message for that ?

@Riders004
Copy link

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

Can you share the code

@vanSnowi
Copy link

a little addition, after i adding a console to see the sent message, it looks like sending a normal message but with the 120363190224821113@newsletter id
Screenshot_2023-12-16-11-24-45-228_com termux

the JID replace 'newsletter' with 's.whatsapp.net' in JID normalization function. Channel messages are not end-to-end encrypted, so we cannot send messages to channels using the 'sendMessage' function.

What function could we use for Newsletter

@vanSnowi
Copy link

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

Does this Work for post in status too?
And which code?

@ernestoyoofi
Copy link
Author

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

Can you give me the short code?

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

@Rippanteq7
Copy link

Does this Work for post in status too? And which code?

U can use sendMessage function for post status

@Raf1nho
Copy link

Raf1nho commented Apr 15, 2024

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?

{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}

I already checked that the user is a channel admin and that the channel id is corret.

@Riders004
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?

{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}

I already checked that the user is a channel admin and that the channel id is corret.

It's not an error it's log maybe your in your bot connection have log

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?

{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}

I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Raf1nho
Copy link

Raf1nho commented Apr 15, 2024

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(

@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(

@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

What version of baileys r u using? working fine for me using the latest version from npm

@Raf1nho
Copy link

Raf1nho commented Apr 16, 2024

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

What version of baileys r u using? working fine for me using the latest version from npm

I'm using 6.6.0. Still trying to find out what is wrong.

I don't get any error, just the "received error in ack" log and the message isn't sent. I've tried adding a timeout to the socket.query method, but then i get a timeout error after the mentioned log.

@ernestoyoofi
Copy link
Author

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(

@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.

@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.

@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

@ernestoyoofi
Copy link
Author

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.

@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?

My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?

My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

@ernestoyoofi
Copy link
Author

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?

My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

Do you use regular WhatsApp or WhatsApp Business?

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?
My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

Do you use regular WhatsApp or WhatsApp Business?

Regular whatsapp

@ernestoyoofi
Copy link
Author

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?
My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

Do you use regular WhatsApp or WhatsApp Business?

Regular whatsapp

Where did you make the script, meaning your bot script, is it from someone's github repository like nurutomo or yourself?

@Rippanteq7
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?
My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

Do you use regular WhatsApp or WhatsApp Business?

Regular whatsapp

Where did you make the script, meaning your bot script, is it from someone's github repository like nurutomo or yourself?

Yeah, I've recoded wabot-aq script

@ernestoyoofi
Copy link
Author

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

I get this error when trying to send message with your solution. Any idea of what I could be missing?
{"level":40,"time":1713197012478,"pid":32697,"hostname":"pop-os","attrs":{"from":"120363261578705116@newsletter","class":"message","id":"16992.57232-7","error":"400","t":"1713197012"},"msg":"received error in ack"}
I already checked that the user is a channel admin and that the channel id is corret.

I have no idea about that. But, was the message successfully sent to the channel?

@Rippanteq7 No, it isn't sent to the channel :(
@Riders004 the only log i get ater trying to send the message is this:

{
  tag: 'ack',
  attrs: {
    from: '120363261578705116@newsletter',
    class: 'message',
    id: '60438.34089-10',
    error: '400',
    t: '1713201479'
  },
  content: undefined
}

i also experience this, but when i move to whatsapp which is registered as beta sometimes it can be sent even though it often still errors with error 400, I don't know what the solution is.
@Rippanteq7 how does your script work properly, or is this an error from the whatsapp server?

Well, I have no idea. My friend tried it also works fine on him

May I know what version of balieys and client you are?, also the same with WhatsApp what version?, is it participating in the beta program?
My version use:

  • WhatsApp : 2.24.9.16 (Beta)
  • Client : 2.2403.2
  • Balieys Package : 6.6.0
  • WhatsApp : 2.24.7.6 (Beta)
  • Client : 2.2403.2
  • Baileys Package : 6.6.0

Do you use regular WhatsApp or WhatsApp Business?

Regular whatsapp

Where did you make the script, meaning your bot script, is it from someone's github repository like nurutomo or yourself?

Yeah, I've recoded wabot-aq script

hm..., is there any other solution if using the original source?

@vanSnowi
Copy link

Does this Work for post in status too? And which code?

U can use sendMessage function for post status

Can you show me an working example

@SatzzDev
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

can send video/image/audio too?

@mzayn
Copy link

mzayn commented May 19, 2024

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

can send video/image/audio too?

+1 same question can send for media like image, video, sound and etc ?

  • also can send text message with link preview ?

@hardknockdays
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

How to send with images or stickers? Any idea please?

@Rippanteq7
Copy link

#820

@salmanytofficial
Copy link

Screenshot_2024-04-13-11-58-49-089_com whatsapp w4y Screenshot_2024-04-13-11-58-58-321_com whatsapp w4y

U can send it using sock.query

Bro can you send me the code of this command to get info of channel by chanel link

@shaheedghazi
Copy link

import pkg from '@whiskeysockets/baileys';
const { proto } = pkg;

export default {
command: ["channel"], // Command to trigger this plugin
description: "Sends a hardcoded message to the WhatsApp channel", // Description for the command
name: "ChannelPlugin", // The name of the plugin
tags: "utility", // The category/tag for the command
run: async (m, { conn }) => {
const channelId = '12039@newsletter'; // Your channel ID
const messageText = 'Hello, this is a hardcoded message from my bot to the channel!'; // The hardcoded message

console.log("Attempting to send message to channel:", channelId);
console.log("Message content:", messageText);

try {
  // Create the message object
  const msg = { conversation: messageText }; 
  const plaintext = proto.Message.encode(msg).finish(); // Encode the message

  const plaintextNode = {
    tag: 'plaintext',
    attrs: {},
    content: plaintext
  };

  const node = {
    tag: 'message',
    attrs: { to: channelId, type: 'text' },
    content: [plaintextNode]
  };

  // Send the message to the channel
  const response = await conn.query(node);
  console.log("Message sent response:", response);

  // Log additional response details
  if (response && response.key) {
    console.log("Message key:", response.key);
    console.log("Message ID:", response.key.id);
  } else {
    console.log("No message key returned.");
  }

  conn.sendMessage(m.chat, { text: "Message sent to the channel!" }, { quoted: m });
} catch (error) {
  console.error("Error sending message to channel:", error);
  if (error.response) {
    console.error("Response from server:", error.response);
  }
  conn.sendMessage(m.chat, { text: "Failed to send message to the channel." }, { quoted: m });
}

},
};

@shaheedghazi
Copy link

shaheedghazi commented Sep 17, 2024

`import pkg from '@whiskeysockets/baileys';
const { proto } = pkg;

export default {
command: ["channel"], // Command to trigger this plugin
description: "Sends a message to the WhatsApp channel", // Description for the command
name: "ChannelPlugin", // The name of the plugin
tags: "utility", // The category/tag for the command
run: async (m, { conn, args }) => {
const channelId = '123@newsletter'; // Your channel ID

// Join the args to form the message text
const messageText = args.join(' ') || 'Hello, this is a default message from my bot!'; // Use provided message or default

console.log("Attempting to send message to channel:", channelId);
console.log("Message content:", messageText);

try {
  // Create the message object
  const msg = { conversation: messageText }; 
  const plaintext = proto.Message.encode(msg).finish(); // Encode the message

  const plaintextNode = {
    tag: 'plaintext',
    attrs: {},
    content: plaintext
  };

  const node = {
    tag: 'message',
    attrs: { to: channelId, type: 'text' },
    content: [plaintextNode]
  };

  // Send the message to the channel
  const response = await conn.query(node);
  console.log("Message sent response:", response);

  // Log additional response details
  if (response && response.key) {
    console.log("Message key:", response.key);
    console.log("Message ID:", response.key.id);
  } else {
    console.log("No message key returned.");
  }

  conn.sendMessage(m.chat, { text: "Message sent to the channel!" }, { quoted: m });
} catch (error) {
  console.error("Error sending message to channel:", error);
  if (error.response) {
    console.error("Response from server:", error.response);
  }
  conn.sendMessage(m.chat, { text: "Failed to send message to the channel." }, { quoted: m });
}

},
};
`

@ernestoyoofi
Copy link
Author

import pkg from '@whiskeysockets/baileys'; const { proto } = pkg;

export default { command: ["channel"], // Command to trigger this plugin description: "Sends a hardcoded message to the WhatsApp channel", // Description for the command name: "ChannelPlugin", // The name of the plugin tags: "utility", // The category/tag for the command run: async (m, { conn }) => { const channelId = '12039@newsletter'; // Your channel ID const messageText = 'Hello, this is a hardcoded message from my bot to the channel!'; // The hardcoded message

console.log("Attempting to send message to channel:", channelId);
console.log("Message content:", messageText);

try {
  // Create the message object
  const msg = { conversation: messageText }; 
  const plaintext = proto.Message.encode(msg).finish(); // Encode the message

  const plaintextNode = {
    tag: 'plaintext',
    attrs: {},
    content: plaintext
  };

  const node = {
    tag: 'message',
    attrs: { to: channelId, type: 'text' },
    content: [plaintextNode]
  };

  // Send the message to the channel
  const response = await conn.query(node);
  console.log("Message sent response:", response);

  // Log additional response details
  if (response && response.key) {
    console.log("Message key:", response.key);
    console.log("Message ID:", response.key.id);
  } else {
    console.log("No message key returned.");
  }

  conn.sendMessage(m.chat, { text: "Message sent to the channel!" }, { quoted: m });
} catch (error) {
  console.error("Error sending message to channel:", error);
  if (error.response) {
    console.error("Response from server:", error.response);
  }
  conn.sendMessage(m.chat, { text: "Failed to send message to the channel." }, { quoted: m });
}

}, };

@shaheedghazi is it possible to send forwarded messages from other channels? like forwarding from channel messages to groups or private chats.

@dn-network
Copy link

How to send a image/videos to channel?

@prabhasha2006
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

It is working! But how to send images and buttons to a channel?

@AbraXas-001
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

can send video/image/audio too?

+1 same question can send for media like image, video, sound and etc ?

  • also can send text message with link preview ?

Good Sir,
Not More than a month, I used "proto" to send interactive messages and buttons and...
Now, it's not working anymore

Any solution or alternative method on how to send such message

@eliafino
Copy link

can your share the sample code for send message for that ?

Sorry for the late reply, here's an example code for sending a text message to a channel

const { proto } = require('@whiskeysockets/baileys')

const msg = { conversation: 'some text' }
const jid = '123@newsletter'

const plaintext = proto.Message.encode(msg).finish()
const plaintextNode = {
	tag: 'plaintext',
	attrs: {},
	content: plaintext
}
const node = {
	tag: 'message',
	attrs: { to: jid, type: 'text' },
	content: [plaintextNode]
}

return sock.query(node)

can send video/image/audio too?

+1 same question can send for media like image, video, sound and etc ?

  • also can send text message with link preview ?

Good Sir, Not More than a month, I used "proto" to send interactive messages and buttons and... Now, it's not working anymore

Any solution or alternative method on how to send such message

So no way to send media with caption to channels?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests