public TranslatorBot(string botId, LanguageType from, LanguageType to, string credentials) { this.from = from; this.to = to; bot = new ICQBotClient(botId); bot.OnMessage += BotOnMessageReceived; bot.OnMessageEdited += BotOnMessageReceived; bot.OnReceiveError += BotOnReceiveError; bot.OnReceiveGeneralError += OnReceiveGeneralError; if (string.IsNullOrWhiteSpace(credentials)) { translationClient = TranslationClient.Create(); } else { GoogleCredential credential = null; using (var credentialStream = new MemoryStream(Encoding.UTF8.GetBytes(credentials))) { credential = GoogleCredential.FromStream(credentialStream); } translationClient = TranslationClient.Create(credential); } }
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; } } }