Esempio n. 1
0
        private async Task <bool> StartSendingAudioMessageAsync(Chat chat, Matbot.Client.Audio audio)
        {
            try
            {
                using (var httpclient = new System.Net.Http.HttpClient())
                {
                    var uri = "https://api.telegram.org/bot" + Token + "/sendAudio?chat_id=" + chat.TelegramId() + "&title=" + audio.Title + "&duration=" + audio.Duration + "&performer=" + audio.Performer;

                    using (var multipartFormDataContent = new System.Net.Http.MultipartFormDataContent())
                    {
                        var streamContent = new System.Net.Http.StreamContent(audio.AudioStream);
                        streamContent.Headers.Add("Content-Type", "application/octet-stream");
                        streamContent.Headers.Add("Content-Disposition", "form-data; name=\"audio\"; filename=\"" + audio.Title + ".mp3\"");
                        multipartFormDataContent.Add(streamContent, "file", "" + audio.Title + ".mp3");

                        using (var message = await httpclient.PostAsync(HttpUtility.UrlPathEncode(uri), multipartFormDataContent))
                        {
                            var contentString = await message.Content.ReadAsStringAsync();
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
 public override bool SendAudioMessage(Chat chat, Matbot.Client.Audio audio)
 {
     StartSendingAudioMessageAsync(chat, audio);
     return(true);
 }