rohitsangwan01 / whatsapp_bot_flutter

Whatsapp bot for flutter desktop
MIT License
40 stars 26 forks source link

Delete message #25

Closed loic-hamdi closed 1 year ago

loic-hamdi commented 1 year ago

Hey,

I am trying to delete a message but I can't for some reasons. It breaks my session and give the error message Evaluation failed: SyntaxError: Invalid or unexpected token

const groupId = "1203631546456456369@g.us";

       client.chat.deleteMessages(
       phone: groupId,
       messageIds: <String>["3EB046A9842E96D7F"],
    );

What is please the good way to do it?

rohitsangwan01 commented 1 year ago

@loic-hamdi i havent worked on the group part yet, can you first check if deleting a normalchat message works ?

loic-hamdi commented 1 year ago

Changing the code to this works in normal chat and group chat ✅

  /// Delete message
  Future deleteMessage({
    required String phone,
    required String messageId,
    bool deleteMediaInDevice = false,
    bool revoke = false,
  }) async {
    return await wpClient.evaluateJs(
      '''WPP.chat.deleteMessage(${phone.phoneParse},${messageId.jsParse}, $deleteMediaInDevice, $revoke);''',
      methodName: "deleteMessage",
    );
  }

Note: Set revoke: true if you want to delete for everyone in group chat

rohitsangwan01 commented 1 year ago

Fixed in https://github.com/rohitsangwan01/whatsapp_bot_flutter/pull/28

loic-hamdi commented 1 year ago

Hi @rohitsangwan01 , for some reasons I can't delete messages anymore. Is it still working on your side?

Where do you get the data from for: phone and messageId ?

Future<dynamic> deleteMessage({
  required String phone,
  required String messageId,
  bool deleteMediaInDevice = false,
  bool revoke = false,
})