public static async Task SendNextMessage(DialogueFrame df, HealthBotContext ctx, users dbUser, IICQBotClient client) { string message = ""; ICQ.Bot.Types.ReplyMarkups.InlineKeyboardMarkup keyboard; string[] buttons = null; if (df.Activity == EnumActivity.Unknown) { if (df.Tag != null) { await client.SendTextMessageAsync( chatId : dbUser.icq_chat_id, text : df.Entity, replyMarkup : null ); } else { return; } } else { message = await GetNextMessage(df, dbUser, ctx, buttons); if (df.Activity == EnumActivity.CallHuman) { dbUser.id_last_question = null; dbUser.is_last_question_system = null; dbUser.chatting = "icq"; } if (dbUser.is_last_question_system.HasValue) { //если нужно прислать картинку //if (dbUser.is_last_question_system.Value && dbUser.id_last_question == (int)SystemMessages.SendBiomark_plot) //{ // using (Stream stream = System.IO.File.OpenRead(dbUser.token + ".png")) // { // await client.SendFileAsync( // chatId: dbUser.icq_chat_id, // document: new ICQ.Bot.Types.InputFiles.InputOnlineFile(stream), // caption: "Ваш график" // ); // } // dbUser.id_last_question = null; // dbUser.is_last_question_system = null; //} } if (message != "") { if (buttons != null) { keyboard = new ICQ.Bot.Types.ReplyMarkups.InlineKeyboardMarkup( buttons.Select(t => new ICQ.Bot.Types.ReplyMarkups.InlineKeyboardButton() { Text = t }) ); await client.SendTextMessageAsync( chatId : dbUser.icq_chat_id, text : message, replyMarkup : keyboard ); } else { await client.SendTextMessageAsync( chatId : dbUser.icq_chat_id, text : message, replyMarkup : null ); } } else { dbUser.id_last_question = null; } } }
public static async Task SendNextMessage(DialogueFrame df, HealthBotContext ctx, users dbUser, Chat chat, ITelegramBotClient client) { string message = ""; ReplyKeyboardMarkup keyboard; string[] buttons = null; if (df.Activity == EnumActivity.Unknown) { if (df.Entity != "") { message = df.Entity; } else { return; } } else { message = await GetNextMessage(df, dbUser, ctx, buttons); if (df.Activity == EnumActivity.CallHuman) { dbUser.id_last_question = null; dbUser.is_last_question_system = null; dbUser.chatting = "telegram"; } if (dbUser.is_last_question_system.HasValue) { //если нужно прислать картинку if (dbUser.is_last_question_system.Value == true && dbUser.id_last_question == (int)SystemMessages.SendBiomark_plot) { using (Stream stream = System.IO.File.OpenRead(dbUser.token + ".png")) { await client.SendPhotoAsync( chatId : chat, photo : stream, caption : "Ваш график" ); } dbUser.id_last_question = null; dbUser.is_last_question_system = null; } } if (message != "") { if (buttons != null) { keyboard = new ReplyKeyboardMarkup { Keyboard = new[] { buttons.Select(t => new Telegram.Bot.Types.ReplyMarkups.KeyboardButton(t)) }, ResizeKeyboard = true }; await client.SendTextMessageAsync( chatId : chat, text : message, replyMarkup : keyboard ); } else { await client.SendTextMessageAsync( chatId : chat, text : message, replyMarkup : new ReplyKeyboardRemove() ); } } else { dbUser.id_last_question = null; } } }
public static async void SendNextMessage(DialogueFrame df, HealthBotContext ctx, users dbUser, CallbackData callbackData, IViberBotClient client) { string message = ""; Keyboard keyboard; string[] buttons = null; if (df.Activity == EnumActivity.Unknown) { if (df.Entity != "") { message = df.Entity; } else { return; } } else { message = await GetNextMessage(df, dbUser, ctx, buttons); if (df.Activity == EnumActivity.CallHuman) { dbUser.id_last_question = null; dbUser.is_last_question_system = null; dbUser.chatting = "viber"; } if (dbUser.is_last_question_system.HasValue) { //если нужно прислать картинку if (dbUser.is_last_question_system.Value == true && dbUser.id_last_question == (int)SystemMessages.SendBiomark_plot) { using (Stream stream = System.IO.File.OpenRead(dbUser.token + ".png")) { await client.SendPictureMessageAsync( new PictureMessage() { Text = "Ваш график", Receiver = callbackData.Sender.Id, MinApiVersion = callbackData.Message.MinApiVersion, TrackingData = callbackData.Message.TrackingData, Media = "https://upload.wikimedia.org/wikipedia/commons/5/57/Viber-logo.png" //viber is lame } ); } dbUser.id_last_question = null; dbUser.is_last_question_system = null; } } if (message != "") { dbUser.id_last_question = (int?)df.Tag; if (buttons != null) { keyboard = new Keyboard() { BackgroundColor = "#32C832", Buttons = buttons.Select(t => new Viber.Bot.KeyboardButton() { Text = t }).ToList() }; await client.SendKeyboardMessageAsync(new KeyboardMessage { Text = message, Keyboard = keyboard, Receiver = callbackData.Sender.Id, MinApiVersion = callbackData.Message.MinApiVersion, TrackingData = callbackData.Message.TrackingData }); } else { await client.SendTextMessageAsync(new TextMessage() { Text = message, Receiver = callbackData.Sender.Id, MinApiVersion = callbackData.Message.MinApiVersion, TrackingData = callbackData.Message.TrackingData }); } } else { dbUser.id_last_question = null; } } }
public static async Task <string> GetNextMessage(DialogueFrame df, users dbUser, HealthBotContext ctx, string[] buttons) { string message = ""; if (df.Activity == EnumActivity.CallHuman) { await SendToZulip(dbUser, ctx, "С Вами общается " + dbUser.fio, true); message = "Ожидание оператора. Для отмены напишите \"Отмена\". (прим. автора: операторов нет, поэтому скорее всего ждать придется очень долго)"; dbUser.id_last_question = null; dbUser.is_last_question_system = null; } else if (df.Activity == EnumActivity.Chatting) { if (df.Entity.ToLower() == "отмена") { dbUser.chatting = ""; message = "Диалог закончен. Спасибо"; } await SendToZulip(dbUser, ctx, df.Entity, false); } else if (df.Activity == EnumActivity.AddBiomarks) { message = ctx.system_messages.Find((int)SystemMessages.PleaseListBiomarks).message; dbUser.id_last_question = (int)SystemMessages.PleaseListBiomarks; dbUser.is_last_question_system = true; } else if (df.Activity == EnumActivity.PrintBiomarks) { message = ctx.system_messages.Find((int)SystemMessages.WhatPeriod).message; dbUser.id_last_question = (int)SystemMessages.WhatPeriod; dbUser.context = ((int)EnumActivity.PrintBiomarks).ToString(); dbUser.is_last_question_system = true; } else if (df.Activity == EnumActivity.Answer || df.Activity == EnumActivity.ReadMyBiomarkers) { if (df.Tag != null) { message = ctx.questions.Where(t => t.id_biomark == (int?)df.Tag).FirstOrDefault().question; dbUser.id_last_question = (int?)df.Tag; } else { return(message); } } else if (df.Activity == EnumActivity.SystemAnswer) { switch (dbUser.id_last_question) { case (int)SystemMessages.SendBiomark_plot: message = App_GetPlot(dbUser.token, DateTime.MinValue, DateTime.Now, dbUser.context); if (message.Length == 0 || message == "К сожалению, приложение \"Здоровье\" не отвечает. попробуйте позже.") { dbUser.id_last_question = null; dbUser.is_last_question_system = null; } break; case (int)SystemMessages.SendToken: message = ctx.system_messages.Find((int)SystemMessages.ThanksForToken).message; dbUser.token = df.Entity; dbUser.id_last_question = null; dbUser.is_last_question_system = null; break; case (int)SystemMessages.YouveEnteredToken: message = ctx.system_messages.Find((int)SystemMessages.SendToken).message; dbUser.id_last_question = (int)SystemMessages.SendToken; break; case (int)SystemMessages.SendBiomark_record: dbUser.context = df.Entity; message = ctx.system_messages.Find((int)SystemMessages.SendBiomarkValue_record).message; dbUser.id_last_question = (int)SystemMessages.SendBiomarkValue_record; dbUser.is_last_question_system = true; break; case (int)SystemMessages.SendBiomarkValue_record: double value; if (double.TryParse(df.Entity.Replace(',', '.'), out value)) { message = App_AddRecord(dbUser.token, dbUser.context, DateTime.Now, value.ToString()); dbUser.id_last_question = null; dbUser.is_last_question_system = null; } else { message = ctx.system_messages.Find((int)SystemMessages.PleaseEnterNumber).message; dbUser.id_last_question = (int)SystemMessages.SendBiomarkValue_record; dbUser.is_last_question_system = true; } break; case (int)SystemMessages.PleaseListBiomarks: try { var biomarks = df.Entity.Split(", "); biomarks dbB = null; foreach (var b in biomarks) { dbB = ctx.biomarks.Where(t => t.name == b).FirstOrDefault(); if (dbB != null && !ctx.users_biomarks.Where(t => t.id_user == dbUser.id).Select(t => t.id_biomark).Contains(dbB.id)) { ctx.users_biomarks.Add(new users_biomarks() { id_user = dbUser.id, id_biomark = dbB.id }); } } message = ctx.system_messages.Find((int)SystemMessages.Success).message; dbUser.id_last_question = null; dbUser.is_last_question_system = null; } catch (Exception e) { message = e.Message; dbUser.id_last_question = null; dbUser.is_last_question_system = null; } break; case (int)SystemMessages.WhatPeriod: { if (dbUser.context == ((int)EnumActivity.PrintBiomarks).ToString()) { switch (df.Entity) { case "сутки": message = PrintBiomarks(dbUser, ctx, 1); dbUser.id_last_question = null; dbUser.is_last_question_system = null; break; case "неделя": message = PrintBiomarks(dbUser, ctx, 7); dbUser.id_last_question = null; dbUser.is_last_question_system = null; break; case "месяц": message = PrintBiomarks(dbUser, ctx, 30); dbUser.id_last_question = null; dbUser.is_last_question_system = null; break; default: message = "Ошибка при вводе перида"; dbUser.id_last_question = null; dbUser.is_last_question_system = null; break; } } if (message == "") { message = "Нет показателей для вывода. Для записи показателей напшите \"Запиши мои показатели\""; } dbUser.context = ""; break; } } } else if (df.Activity == EnumActivity.LoadFile) { message = ctx.system_messages.Find((int)SystemMessages.ImageSaved).message; } else if (df.Activity == EnumActivity.ConversationStart) { buttons = new[] { "Да", "Нет" }; message = ctx.system_messages.Find((int)SystemMessages.WantToStart).message; dbUser.id_last_question = (int)SystemMessages.WantToStart; dbUser.is_last_question_system = true; } else if (df.Activity == EnumActivity.ConversationStartAnswer) { message = ctx.system_messages.Find((int)SystemMessages.Hello).message; } else if (df.Activity == EnumActivity.SendToApp) { message = ctx.system_messages.Find((int)SystemMessages.SendBiomark_record).message; dbUser.id_last_question = (int)SystemMessages.SendBiomark_record; dbUser.is_last_question_system = true; } else if (df.Activity == EnumActivity.GetPlot) { message = ctx.system_messages.Find((int)SystemMessages.SendBiomark_plot).message; dbUser.id_last_question = (int)SystemMessages.SendBiomark_plot; dbUser.is_last_question_system = true; } else if (df.Activity == EnumActivity.ConnectToMobileApp) { if (dbUser.token == null || dbUser.token.Length == 0) { message = ctx.system_messages.Find((int)SystemMessages.SendToken).message; dbUser.id_last_question = (int)SystemMessages.SendToken; dbUser.is_last_question_system = true; } else { message = ctx.system_messages.Find((int)SystemMessages.YouveEnteredToken).message; dbUser.id_last_question = (int)SystemMessages.YouveEnteredToken; dbUser.is_last_question_system = true; } } else if (df.Activity == EnumActivity.SecretMessage) { message = ctx.system_messages.Find((int)SystemMessages.SecretMessage).message; //message = App_AddRecord(dbUser.token, "шаги", DateTime.Now, "10.5"); //message = App_GetPlot(dbUser.token, DateTime.MinValue, DateTime.Now, "шаги"); } else if (df.Activity == EnumActivity.Unknown) { message = df.Entity; } return(message); }