public async Task SendToMany(IEnumerable <long> chatIds, string message, CoreKeyboard keyboard = null, IEnumerable <string> attachments = null) { message = TrimText(message); foreach (var chunk in chatIds.Chunk(ChunkLimit)) { try { await _vkApi.Messages.SendToUserIdsAsync(new MessagesSendParams { UserIds = chunk, Message = message, Keyboard = KeyboardConverter.FromCoreToVk(keyboard, true), Attachments = ConvertAttachments(attachments), RandomId = GetRandomId() }); await Task.Delay(100); } catch (Exception e) { _logger.Error(e, "Ошибка при отправке сообщения"); } } }
private async Task MessageEvent(MessageEvent messageEvent) { var mappedToMessage = _mapper.Map <Message>(messageEvent); await _commandsService.ExecuteCommand(mappedToMessage, OnSuccess, OnFailed); async Task OnSuccess(IResult res) { try { await _vkApi.Messages.EditAsync(new MessageEditParams() { PeerId = messageEvent.PeerId.GetValueOrDefault(0), ConversationMessageId = messageEvent.ConversationMessageId, Keyboard = KeyboardConverter.FromCoreToVk(res.Keyboard, true), Message = res.Message }); } catch { await _sender.Send(messageEvent.PeerId.GetValueOrDefault(0), res.Message, res.Keyboard); } } async Task OnFailed(IResult res) { await _vkApi.Messages.SendMessageEventAnswerAsync(messageEvent.EventId, messageEvent.UserId.GetValueOrDefault(0), messageEvent.PeerId.GetValueOrDefault(0), new EventData() { Type = MessageEventType.SnowSnackbar, Text = res.Message }); } }
public Task Send(long chatId, string message, CoreKeyboard keyboard = null, IEnumerable <string> attachments = null) { message = TrimText(message); var replyMarkup = KeyboardConverter.FromCoreToTg(keyboard); return(_botClient.SendTextMessageAsync(chatId, message, replyMarkup: replyMarkup)); }
public Task Send(long chatId, string message, CoreKeyboard keyboard = null, IEnumerable <string> attachments = null) { message = TrimText(message); return(_vkApi.Messages.SendAsync(new MessagesSendParams { PeerId = chatId, Message = message, Keyboard = KeyboardConverter.FromCoreToVk(keyboard, true), Attachments = ConvertAttachments(attachments), RandomId = GetRandomId() })); }
private async Task HandleCallback(CallbackQuery query) { var msg = _mapper.Map <Message>(query); await _commandsService.ExecuteCommand(msg, OnAnyResult, OnAnyResult); async Task OnAnyResult(IResult res) { await _botClient.AnswerCallbackQueryAsync(query.Id); await _botClient.EditMessageTextAsync(new ChatId(query.From.Id), query.Message.MessageId, res.Message); if (res.Keyboard.IsInline) { await _botClient.EditMessageReplyMarkupAsync(new ChatId(query.From.Id), query.Message.MessageId, KeyboardConverter.FromCoreToTg(res.Keyboard) as InlineKeyboardMarkup); } } }