TLSharp
TLSharp copied to clipboard
Deleting a message by user id
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);
}`