Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.05k stars 490 forks source link

How to delete a chat? #552

Open danymx24 opened 3 years ago

danymx24 commented 3 years ago

I searched the code and I cant find the way to delete a chat, is there any way to do it?

Thanks!!

beshoo commented 3 years ago

https://github.com/Rhymen/go-whatsapp/issues/100

danymx24 commented 3 years ago

I don't understand why you close it, I want to delete a chat or a chat group, not a single message!!

beshoo commented 3 years ago

Sorry, by mistake. :)

danymx24 commented 3 years ago

Ok, So is there any way to delete a chat or a chat group?

beshoo commented 3 years ago

Well, here is the JSON to delete a chat

Message Tag: 106.--34
got unhandled node of desc: chat
Node {
    desc: "chat",
    attributes: {
        "index": 07566521A2167BC62B62DC982CBE27BE,
        "type": delete,
        "owner": false,
        "jid": 213663331175@c.us,
    },
    content: None,
}

It is a binary message. I am not sure about the index But it seems each chat has its own Index!

beshoo commented 3 years ago

UNTESTED

func (wac *Conn) DeleteChat(jid, id string) (<-chan string, error) {
ts := time.Now().Unix()
tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount)

n := binary.Node{
    Description: "action",
    Attributes: map[string]string{
        "type":  "set",
        "epoch": strconv.Itoa(wac.msgCount),
    },
    Content: []interface{}{
        binary.Node{
            Description: "chat",
            Attributes: map[string]string{
                "index": id,
                "type":  "delete",
                "from":  jid,
                                "owner": false,
            },
            Content: "None",
        },
    },
}

return wac.writeBinary(n, message, ignore, tag)
}
Ased2235 commented 3 years ago

UNTESTED

func (wac *Conn) DeleteChat(jid, id string) (<-chan string, error) {
ts := time.Now().Unix()
tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount)

n := binary.Node{
  Description: "action",
  Attributes: map[string]string{
      "type":  "set",
      "epoch": strconv.Itoa(wac.msgCount),
  },
  Content: []interface{}{
      binary.Node{
          Description: "chat",
          Attributes: map[string]string{
              "index": id,
              "type":  "delete",
              "from":  jid,
                                "owner": false,
          },
          Content: "None",
      },
  },
}

return wac.writeBinary(n, message, ignore, tag)
}

Hello, first of all, how are you? It's been a while since we talked & you didn't replied to my msg too. Now about the code, i think you should pass ower too as it's required in clear chat function. Owner means last msg owner not as in chat. Correct me if I missed something.

beshoo commented 3 years ago

Regarding the owner, I believe we need to test this more deeper. It is just a fast assumption.

Os. Check your WhatsApp ❤️❤️

Ased2235 commented 3 years ago

Regarding the owner, I believe we need to test this more deeper. It is just a fast assumption.

Have you tested it yet or should i? as i don't really need that one. Os. Check your WhatsApp

My old account is ded, i msgs you using +62 xD

beshoo commented 3 years ago

Hi, No i did not test it since I have no time. And I dont need it anyway.

But I provide how it should be, and he has to test anf find how to use it.

Please reping me on my whatsapp since I cant find your number.

Or email me your number

@.***

Regard

On Sat, Apr 24, 2021, 7:05 PM Ased2235 @.***> wrote:

Regarding the owner, I believe we need to test this more deeper. It is just a fast assumption.

Have you tested it yet or should i? as i don't really need that one.

Os. Check your WhatsApp

My old account is ded, i msgs you using +62 xD

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Rhymen/go-whatsapp/issues/552#issuecomment-826114528, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLT23PYQKZJA2VHPEUPRLTKLT3RANCNFSM43LSKBNA .

jwm947 commented 3 years ago

I tried following approach unsuccessfully :( The function returned {"status":"499"}

I guess we should find how to get the index somewhere, any idea? I will check if index= first or last message id.

// Delete a Chat
func (wac *Conn) DeleteChat(jid string) (<-chan string, error) {
    ts := time.Now().Unix()
    tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount) // 1st try
    tag = "07566521A2167BC62B62DC982CBE27BE" // 2nd try
    n := binary.Node{
        Description: "action",
        Attributes: map[string]string{
            "type":  "set",
            "epoch": strconv.Itoa(wac.msgCount),
        },
        Content: []interface{}{
            binary.Node{
                Description: "chat",
                Attributes: map[string]string{
                    "index": tag,
                    "type":  "delete",
                    "from":  jid,
                    "owner": "false",
                },
                Content: nil,
            },
        },
    }

    return wac.writeBinary(n, chat, ignore, tag)
}
jwm947 commented 3 years ago

@beshoo we figure out! The index is the last message id, we tested and now is working! Follows a pr with an example.