TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

Deleting a message by user id

Open MatteoMark opened this issue 5 years ago • 0 comments

Hello, I was wondering if there is any way to delete a message sent by tlsharp by the id of an user. I noticed that it is possible to delete an entire chat through it's id, so I thought that maybe it's just a matter of request formatting. Can someone help me?

`That's the code I'm using to send messages:

        try
        {
            var client = GlobalVar.client;
            var destinationNumber = _destinationNumber;
            if (string.IsNullOrWhiteSpace(destinationNumber)) // check if the number has a correct format
                throw new Exception($"Please fill the '{nameof(destinationNumber)}' setting in app.config file first");
            // this is because the contacts in the address come without the "+" prefix
            var normalizedNumber = destinationNumber.StartsWith("+") ?
                destinationNumber.Substring(1, destinationNumber.Length - 1) :
                destinationNumber;

            var result = await client.GetContactsAsync(); // get contact

            var user = result.Users
                .OfType<TLUser>()
                .FirstOrDefault(x => x.Phone == normalizedNumber); // number normalization

            if (user == null) // if user does not exists
            {
                throw new System.Exception("Number was not found in Contacts List of user: " + destinationNumber);
            }
            else
            {
                await client.SendTypingAsync(new TLInputPeerUser() { UserId = user.Id });
                await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, msg); // send text
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }`

MatteoMark avatar Oct 06 '20 15:10 MatteoMark