public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var message = await argument; var tr = new BingTranslatorClient(Config.TranslatorKey, Config.TranslatorSecret); var res = await tr.Translate(message.Text, "ru-RU", "en-US"); await context.PostAsync(res); context.Wait(MessageReceivedAsync); }
protected override async Task <string> GetLuisQueryTextAsync(IDialogContext context, IMessageActivity message) { Translator = new BingTranslatorClient(Config.TranslatorKey, Config.TranslatorSecret); var baseLuisText = await base.GetLuisQueryTextAsync(context, message); Locale = message.Locale == null ? "en-US" : message.Locale; if (message.Locale != null && message.Locale != "en-US") { return(await Translator.Translate(baseLuisText, message.Locale, "en-US")); } else { return(baseLuisText); } }
public static async Task PostWithTranslationAsync(this IBotToUser context, string message, string messageLocale, string userLocale) { if (messageLocale == null) throw new ArgumentNullException(nameof(messageLocale)); if (userLocale == null) throw new ArgumentNullException(nameof(userLocale)); try { var bingTranslatorClient = new BingTranslatorClient("Test187871", "dAnT3r/eIc8KedBRUgRCV+juxpf4Wl312jn1Bd2SXzk="); var translatedMessage = await bingTranslatorClient.Translate(message, messageLocale, userLocale); await context.PostAsync(translatedMessage, userLocale); } catch (Exception e) { await context.PostAsync("Translator service problems, please try again later", "en-US"); } }
protected override async Task <string> GetLuisQueryTextAsync(IDialogContext context, IMessageActivity message) { var baseLuisText = await base.GetLuisQueryTextAsync(context, message); if (message.Locale != null && message.Locale != "en-US") { try { var bingTranslatorClient = new BingTranslatorClient(AccessKeys.BingTranslatorSubscriptionKey); return(await bingTranslatorClient.Translate(baseLuisText, "en-US", message.Locale)); } catch (Exception e) { throw; } } return(baseLuisText); }
public static async Task PostWithTranslationAsync(this IBotToUser context, string message, string messageLocale, string userLocale) { if (messageLocale == null) { throw new ArgumentNullException(nameof(messageLocale)); } if (userLocale == null) { throw new ArgumentNullException(nameof(userLocale)); } try { var bingTranslatorClient = new BingTranslatorClient("Test187871", "dAnT3r/eIc8KedBRUgRCV+juxpf4Wl312jn1Bd2SXzk="); var translatedMessage = await bingTranslatorClient.Translate(message, messageLocale, userLocale); await context.PostAsync(translatedMessage, userLocale); } catch (Exception e) { await context.PostAsync("Translator service problems, please try again later", "en-US"); } }