Ejemplo n.º 1
0
        public async Task <SendMessageResult> SendMessageAsync(MessageCategory category, MessageType type, MessageRarity rarity, long chatId)
        {
            var redalertMessage = false;

            var message = await _messageTextProvider.GetMessage(category, type, rarity, chatId);

            if (message == null)
            {
                message.Text    = Const.RedAlertMessage;
                redalertMessage = true;
            }

            try
            {
                if (message.ImageUrl == null)
                {
                    await _telegramBotClientWrapper.Client.SendTextMessageAsync(chatId, message.Text);
                }
                else
                {
                    await _telegramBotClientWrapper.Client.SendPhotoAsync(chatId, message.ImageUrl, caption : message.Text);
                }
            }
            catch (ApiRequestException ex)
            {
                if (ex.Message.Contains("blocked"))
                {
                    var result = SendMessageResult.CreateBlocked();
                    return(result);
                }

                _logger.LogError(ex.ToString());

                return(SendMessageResult.CreateUnknown());
            }

            if (redalertMessage)
            {
                _logger.LogInformation($"RedAlert message sent. ChatId: {chatId}.");
            }
            else
            {
                _logger.LogInformation($"Message sent. " +
                                       $"ChatId: {chatId}, " +
                                       $"Category: {category}, " +
                                       $"Type: {type}, " +
                                       $"Rarity: {rarity}.");
            }

            return(SendMessageResult.CreateSuccess());
        }
Ejemplo n.º 2
0
        public SendMessageResult CreateSandMessageResult(string response)
        {
            if (string.IsNullOrEmpty(response))
            {
                return(SendMessageResult.CreateFailure("No server Response"));
            }

            if (response.Contains("Error"))
            {
                return(SendMessageResult.CreateFailure(response));
            }

            return(SendMessageResult.CreateSuccess(response));
        }