RaHa VelShodeh
RaHa VelShodeh

Reputation: 93

How can send audio and video files to Telegram via TLSharp in c#?

I'm working with TLSharp NuGet in my C# code and I can send photo files via below code:

var request = new Message_SendMediaRequest(
new InputPeerContactConstructor(contactId),
new InputMediaUploadedPhotoConstructor(file));

but when I try to send audio or video files and I change

InputMediaUploadedPhotoConstructor(file) to InputMediaUploadedAudioConstructor(file, duration)
I can't do it and I have this error message:
"Object reference not set to an instance of an object.".
What should I do? Thanks.

Upvotes: 1

Views: 1308

Answers (1)

RaHa VelShodeh
RaHa VelShodeh

Reputation: 93

At fisrt I used TLSharp Nuget and Dlls but when I deploy the source code to my project and set IP server and it's port and api id and api hash, my problem to be solved:

public async Task<bool> SendAudioMessage(int contactId, InputFile file, int duration)
{
var request = new Message_SendMediaRequest(
new InputPeerContactConstructor(contactId),
new InputMediaUploadedAudioConstructor(file, duration));
await _sender.Send(request);
await _sender.Recieve(request);
return true;
}

Upvotes: 1

Related Questions