Exemple #1
0
        private async Task <TelegramClient> ConnectTelegramClientAsync(TelegramHelperVo telegramHelperVo)
        {
            var client = _telegramClientFactory.CreateClient(telegramHelperVo.Client.Id, telegramHelperVo.Client.Hash);

            _logger.LogInformation("Connecting the Telegram Client.");
            await client.ConnectAsync();

            return(client);
        }
        protected void SendMessage(string token, string chatId, TelegramMessage message)
        {
            SelfLog.WriteLine($"Trying to send message to chatId '{chatId}': '{message}'.");

            var telegramClient = TelegramClientFactory.CreateClient(token, proxy);

            var sendMessageTask = telegramClient.PostAsync(message: message, chatId: chatId);

            Task.WaitAll(sendMessageTask);

            var sendMessageResult = sendMessageTask.Result;

            if (sendMessageResult != null)
            {
                SelfLog.WriteLine($"Message sent to chatId '{chatId}': '{sendMessageResult.StatusCode}'.");
            }
        }