private void OnWizardCreate() { if (witBuiltInIndex == 0) { WitAuthUtility.ServerToken = serverToken; } if (WitAuthUtility.IsServerTokenValid()) { if (witBuiltInIndex > 0) { SettingsWindow.CreateConfiguration(WitAuthUtility.ServerToken, builtinAppNames[witBuiltInIndex], successAction); } else { SettingsWindow.CreateConfiguration(WitAuthUtility.ServerToken, null, successAction); } Close(); } else { throw new ArgumentException( "Server token is not valid. Please set a server token."); } }
private void ApplyToken(string token) { if (!string.IsNullOrEmpty(token) && WitAuthUtility.IsServerTokenValid(token)) { RefreshAppData(WitAuthUtility.GetAppId(token), token); } }
public static void UpdateTokenData(string serverToken, Action updateComplete = null) { if (!WitAuthUtility.IsServerTokenValid(serverToken)) { return; } var listRequest = WitRequestFactory.ListAppsRequest(serverToken, 10000); listRequest.onResponse = (r) => { if (r.StatusCode == 200) { var applications = r.ResponseData.AsArray; for (int i = 0; i < applications.Count; i++) { if (applications[i]["is_app_for_token"].AsBool) { var application = WitApplication.FromJson(applications[i]); EditorForegroundRunner.Run(() => { WitAuthUtility.SetAppServerToken(application.id, serverToken); updateComplete?.Invoke(); }); break; } } } else { Debug.LogError(r.StatusDescription); } }; listRequest.Request(); }
protected virtual void ValidateAndClose() { WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { // Create configuration int index = CreateConfiguration(serverToken); if (index != -1) { // Complete Close(); WitConfiguration c = WitConfigurationUtility.WitConfigs[index]; if (successAction == null) { WitWindowUtility.OpenConfigurationWindow(c); } else { successAction(c); } } } else { throw new ArgumentException(WitTexts.Texts.SetupSubmitFailLabel); } }
protected virtual void DrawWit() { // Recommended max size based on EditorWindow.maxSize doc for resizable window. if (welcomeSizeSet) { welcomeSizeSet = false; maxSize = new Vector2(4000, 4000); } titleContent = new GUIContent("Wit Configuration"); GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); if (null == serverToken) { serverToken = WitAuthUtility.ServerToken; } serverToken = EditorGUILayout.PasswordField("Server Access Token", serverToken); if (GUILayout.Button(WitStyles.PasteIcon, WitStyles.ImageIcon)) { serverToken = EditorGUIUtility.systemCopyBuffer; WitAuthUtility.ServerToken = serverToken; RefreshContent(); } if (GUILayout.Button("Relink", GUILayout.Width(75))) { if (WitAuthUtility.IsServerTokenValid(serverToken)) { WitConfigurationEditor.UpdateTokenData(serverToken, RefreshContent); } WitAuthUtility.ServerToken = serverToken; RefreshContent(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); var configChanged = DrawWitConfigurationPopup(); if (GUILayout.Button("Create", GUILayout.Width(75))) { CreateConfiguration(); } GUILayout.EndHorizontal(); if (witConfiguration && (configChanged || !witEditor)) { WitConfiguration config = (WitConfiguration)witConfiguration; SetWitEditor(); } if (witConfiguration && witEditor) { witEditor.OnInspectorGUI(); } GUILayout.EndVertical(); }
public static void ShowWindow() { if (WitAuthUtility.IsServerTokenValid()) { GetWindow <WitWindow>("Wit Settings"); } else { WitWelcomeWizard.ShowWizard(ShowWindow); } }
protected override void OnDrawContent() { if (!WitAuthUtility.IsServerTokenValid()) { DrawWelcome(); } else { DrawWit(); } }
public static void ShowSettingsWindow() { if (WitAuthUtility.IsServerTokenValid()) { GetWindow <SettingsWindow>("Welcome to Voice SDK"); } else { var wizard = ScriptableWizard.DisplayWizard <WelcomeWizard>("Welcome to Voice SDK", "Link"); wizard.successAction = ShowSettingsWindow; } }
public void Initialize() { WitAuthUtility.InitEditorTokens(); configuration = target as WitConfiguration; currentToken = WitAuthUtility.GetAppServerToken(configuration); if (WitAuthUtility.IsServerTokenValid(currentToken) && !string.IsNullOrEmpty(configuration?.clientAccessToken)) { configuration?.UpdateData(() => { EditorForegroundRunner.Run(() => EditorUtility.SetDirty(configuration)); }); } }
protected void ValidateAndClose() { WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { Close(); WitWindow.ShowWindow(); successAction?.Invoke(); } else { throw new ArgumentException("Please enter a valid token before linking."); } }
/// <summary> /// Gets the app info and client id that is associated with the server token being used /// </summary> /// <param name="serverToken">The server token to use to get the app config</param> /// <param name="action"></param> public static void FetchAppConfigFromServerToken(this WitConfiguration configuration, string serverToken, Action action) { if (WitAuthUtility.IsServerTokenValid(serverToken)) { FetchApplicationFromServerToken(configuration, serverToken, () => { FetchClientToken(configuration, () => { configuration.UpdateData(action); }); }); } else { Debug.LogError($"No server token set for {configuration.name}."); } }
protected override bool DrawWizardGUI() { maxSize = minSize = new Vector2(400, 375); BaseWitWindow.DrawHeader("https://wit.ai/apps"); GUILayout.BeginHorizontal(); GUILayout.Space(16); GUILayout.BeginVertical(); GUILayout.Label("Build Natural Language Experiences", WitStyles.LabelHeader); GUILayout.Label( "Empower people to use your product with voice and text", WitStyles.LabelHeader2); GUILayout.EndVertical(); GUILayout.Space(16); GUILayout.EndHorizontal(); GUILayout.Space(32); BaseWitWindow.BeginCenter(296); GUILayout.BeginHorizontal(); GUILayout.Label("Paste your Server Access Token here", WitStyles.Label); GUILayout.FlexibleSpace(); if (GUILayout.Button(WitStyles.PasteIcon, WitStyles.Label)) { serverToken = EditorGUIUtility.systemCopyBuffer; WitAuthUtility.ServerToken = serverToken; ValidateAndClose(); } GUILayout.EndHorizontal(); if (null == serverToken) { serverToken = WitAuthUtility.ServerToken; } serverToken = EditorGUILayout.PasswordField(serverToken, WitStyles.TextField); BaseWitWindow.EndCenter(); return(WitAuthUtility.IsServerTokenValid()); }
private void UpdateStep() { #if UNITY_EDITOR var appVoiceExperience = FindObjectOfType <AppVoiceExperience>(); string[] guids = AssetDatabase.FindAssets("t:WitConfiguration"); if (guids.Length == 0) { currentStep = Step.SetupWit; } else if (!appVoiceExperience) { currentStep = Step.AddVoiceExperiences; } else if (!appVoiceExperience.RuntimeConfiguration.witConfiguration) { currentStep = Step.SetConfig; appVoiceExperience.RuntimeConfiguration.witConfiguration = AssetDatabase.LoadAssetAtPath <WitConfiguration>( AssetDatabase.GUIDToAssetPath(guids[0])); } else if (!WitAuthUtility.IsServerTokenValid()) { currentStep = Step.MissingServerToken; } else if (string.IsNullOrEmpty(appVoiceExperience.RuntimeConfiguration?.witConfiguration .clientAccessToken)) { currentStep = Step.MissingClientToken; } else { currentStep = Step.Ready; } instructionText.text = steps[(int)currentStep]; #endif }
// Token valid check public static bool IsServerTokenValid(string serverToken) { return(!string.IsNullOrEmpty(serverToken) && WitAuthUtility.IsServerTokenValid(serverToken)); }
protected virtual void DrawWelcome() { titleContent = WitStyles.welcomeTitleContent; if (!welcomeSizeSet) { minSize = new Vector2(450, 686); maxSize = new Vector2(450, 686); welcomeSizeSet = true; } scroll = GUILayout.BeginScrollView(scroll); GUILayout.Label("Build Natural Language Experiences", WitStyles.LabelHeader); GUILayout.Label( "Enable people to interact with your products using voice and text.", WitStyles.LabelHeader2); GUILayout.Space(32); BeginCenter(296); GUILayout.BeginHorizontal(); GUILayout.Label("Paste your Server Access Token here", WitStyles.Label); GUILayout.FlexibleSpace(); if (GUILayout.Button(WitStyles.PasteIcon, WitStyles.Label)) { serverToken = EditorGUIUtility.systemCopyBuffer; WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { RefreshContent(); } } GUILayout.EndHorizontal(); if (null == serverToken) { serverToken = WitAuthUtility.ServerToken; } GUILayout.BeginHorizontal(); serverToken = EditorGUILayout.PasswordField(serverToken, WitStyles.TextField); if (GUILayout.Button("Link", GUILayout.Width(75))) { WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { RefreshContent(); } } GUILayout.EndHorizontal(); EndCenter(); BeginCenter(); GUILayout.Label("or", WitStyles.Label); EndCenter(); BeginCenter(); if (GUILayout.Button(WitStyles.ContinueButton, WitStyles.Label, GUILayout.Height(50), GUILayout.Width(296))) { Application.OpenURL("https://wit.ai"); } GUILayout.Label( "Please connect with Facebook login to continue using Wit.ai by clicking on the “Continue with Github Login” and following the instructions provided.", WitStyles.Label, GUILayout.Width(296)); EndCenter(); BeginCenter(); GUILayout.Space(16); EndCenter(); GUILayout.EndScrollView(); }
protected override void DrawWelcome() { titleContent = WitStyles.welcomeTitleContent; if (!welcomeSizeSet) { minSize = new Vector2(450, 350); maxSize = new Vector2(450, 350); welcomeSizeSet = true; } scroll = GUILayout.BeginScrollView(scroll); GUILayout.Label("Build Natural Language Experiences", WitStyles.LabelHeader); GUILayout.Label( "Empower people to use your product with voice and text", WitStyles.LabelHeader2); GUILayout.Space(32); BeginCenter(296); GUILayout.Label("Select language to use Built-In NLP", WitStyles.Label); int witBuiltInIndex = -1; int selected = EditorGUILayout.Popup("", witBuiltInIndex, AppBuiltIns.appNames); if (selected != witBuiltInIndex) { witBuiltInIndex = selected; WitAuthUtility.ServerToken = AppBuiltIns.builtInPrefix + AppBuiltIns.appNames[witBuiltInIndex]; CreateConfiguration(AppBuiltIns.appNames[witBuiltInIndex]); RefreshContent(); } EndCenter(); GUILayout.Space(16); BeginCenter(296); GUILayout.BeginHorizontal(); GUILayout.Label("Paste your Server Access Token here", WitStyles.Label); GUILayout.FlexibleSpace(); if (GUILayout.Button(WitStyles.PasteIcon, WitStyles.Label)) { serverToken = EditorGUIUtility.systemCopyBuffer; WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { RefreshContent(); } } GUILayout.EndHorizontal(); if (null == serverToken) { serverToken = WitAuthUtility.ServerToken; } GUILayout.BeginHorizontal(); serverToken = EditorGUILayout.PasswordField(serverToken, WitStyles.TextField); if (GUILayout.Button("Link", GUILayout.Width(75))) { WitAuthUtility.ServerToken = serverToken; if (WitAuthUtility.IsServerTokenValid()) { RefreshContent(); } } GUILayout.EndHorizontal(); EndCenter(); GUILayout.EndScrollView(); }
protected override bool DrawWizardGUI() { base.DrawWizardGUI(); GUILayout.BeginHorizontal(); GUILayout.Space(24); GUILayout.BeginVertical(); GUILayout.Label("Building App Voice Experiences", WitStyles.LabelHeader, GUILayout.Height(64)); GUILayout.Label( "Empowering developers to build engaging voice interactions.", GUILayout.Height(EditorGUIUtility.singleLineHeight * 2)); GUILayout.EndVertical(); GUILayout.Space(24); GUILayout.EndHorizontal(); BaseWitWindow.BeginCenter(296); GUILayout.Label("Select language to use Built-In NLP", WitStyles.Label); int selected = EditorGUILayout.Popup("", witBuiltInIndex, builtinAppNames); if (selected != witBuiltInIndex) { witBuiltInIndex = selected; WitAuthUtility.ServerToken = AppBuiltIns.builtInPrefix + AppBuiltIns.appNames[witBuiltInIndex]; } BaseWitWindow.EndCenter(); if (witBuiltInIndex <= 0) { GUILayout.Space(16); BaseWitWindow.BeginCenter(296); GUILayout.BeginHorizontal(); var color = "blue"; if (EditorGUIUtility.isProSkin) { color = "#ccccff"; } if (GUILayout.Button( $"Paste your <color={color}>Wit.ai</color> Server Access Token here", WitStyles.Label)) { Application.OpenURL("https://wit.ai/apps"); } GUILayout.FlexibleSpace(); if (GUILayout.Button(WitStyles.PasteIcon, WitStyles.Label)) { serverToken = EditorGUIUtility.systemCopyBuffer; WitAuthUtility.ServerToken = serverToken; } GUILayout.EndHorizontal(); if (null == serverToken) { serverToken = WitAuthUtility.ServerToken; } serverToken = EditorGUILayout.PasswordField(serverToken); BaseWitWindow.EndCenter(); } return(WitAuthUtility.IsServerTokenValid()); }