using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Text; using SvetoforVKBot.App_Start; using SvetoforVKBot.Models.Updates; using VkNet; using VkNet.Enums.SafetyEnums; using VkNet.Model.Keyboard; using VkNet.Model.RequestParams; namespace SvetoforVKBot.Models.Commands.LK.Consultation { public class GetConsultationCommand { public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db) { var chatId = update.@object.message.from_id; MessagesSendParams @params = new MessagesSendParams(); MessagesSendParams @params2 = new MessagesSendParams(); var keyboardBuilder = new KeyboardBuilder().Clear(); try { if (update.@object.message.text.Length > 0) { var ids = new long[] { chatId }; var user = db.Users.Single(usr => usr.chatId == chatId); user.question = update.@object.message.text.Trim(); user.tag = "Личный кабинет"; db.SaveChanges(); keyboardBuilder .AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Default); @params.Keyboard = keyboardBuilder.Build(); @params.Message = "✅Вопрос принят. Менеджер ответит Вам в ближайшее время!\n"; @params.UserId = chatId; @params.RandomId = GetRandomId(); client.Messages.SendAsync(@params); @params2.Message = "❓Вопрос. \nСсылка на диалог: " + ((WebConfiguration)ConfigurationManager.GetSection("VKApi")).GroupDialogsLink + chatId; List listFrwMsg = new List() { update.@object.message.id }; @params2.PeerId = 2000000002; //@params2.UserId = 59111081; @params2.ForwardMessages = listFrwMsg; @params2.RandomId = GetRandomId(); client.Messages.Send(@params2); } else { @params.Message = "Не распознал сообщение 😕 Попробуйте, пожалуйста, ещё раз"; @params.UserId = chatId; @params.RandomId = GetRandomId(); client.Messages.SendAsync(@params); } } catch (Exception ee) { @params.Message = "‼Ошибка в GetReportCommentCommand: " + ee.Message; @params.Attachments = null; @params.Keyboard = null; @params.UserId = 59111081; @params.RandomId = GetRandomId(); client.Messages.SendAsync(@params); } } private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create(); public int GetRandomId() { var intBytes = new byte[4]; Rng.GetBytes(intBytes); return BitConverter.ToInt32(intBytes, 0); } } }