Пример #1
0
        private void RefreshAppData(string appId, string token = "")
        {
            var refreshToken = WitAuthUtility.GetAppServerToken(appId, token);

            if (string.IsNullOrEmpty(refreshToken) &&
                string.IsNullOrEmpty(appId) &&
                !string.IsNullOrEmpty(configuration?.application?.id))
            {
                refreshToken = WitAuthUtility.GetAppServerToken(configuration.application.id,
                                                                WitAuthUtility.ServerToken);
                appId = WitAuthUtility.GetAppId(refreshToken);
                if (string.IsNullOrEmpty(appId))
                {
                    UpdateTokenData(refreshToken, () =>
                    {
                        appId = WitAuthUtility.GetAppId(refreshToken);
                        if (appId == configuration.application.id)
                        {
                            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
                            {
                                currentToken = refreshToken;
                                WitAuthUtility.SetAppServerToken(configuration.application.id, currentToken);
                                EditorUtility.SetDirty(configuration);
                                EditorForegroundRunner.Run(Repaint);
                                appConfigurationFoldout = false;
                            });
                        }
                    });
                    return;
                }

                if (appId == configuration.application.id)
                {
                    refreshToken = WitAuthUtility.ServerToken;
                }
            }

            if (currentToken != refreshToken)
            {
                currentToken = refreshToken;
            }

            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
            {
                currentToken = refreshToken;
                EditorForegroundRunner.Run(Repaint);
                appConfigurationFoldout = false;
            });
        }
Пример #2
0
        private static void DoUpdateData(WitConfiguration configuration, Action onUpdateComplete)
        {
            EditorForegroundRunner.Run(() =>
            {
                if (!string.IsNullOrEmpty(
                        WitAuthUtility.GetAppServerToken(configuration.application.id)))
                {
                    var intentsRequest        = configuration.ListIntentsRequest();
                    intentsRequest.onResponse =
                        (r) => ListEntities(r, configuration, onUpdateComplete);

                    configuration.application?.UpdateData(intentsRequest.Request);
                }
            });
        }
Пример #3
0
 /// <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}.");
     }
 }
Пример #4
0
        // Reload app data if needed
        private void ReloadAppData()
        {
            // Check for changes
            string checkName = "";
            string checkID   = "";

            if (configuration != null && configuration.application != null)
            {
                checkName = configuration.application.name;
                checkID   = configuration.application.id;
            }
            // Reset
            if (!string.Equals(_appName, checkName) || !string.Equals(_appID, checkID))
            {
                _appName     = checkName;
                _appID       = checkID;
                _serverToken = WitAuthUtility.GetAppServerToken(configuration);
            }
        }
Пример #5
0
        // Refresh client data
        private static void SetClientData(WitConfiguration configuration, string serverToken, Action <string> onSetComplete)
        {
            // Invalid app ID
            string appID = GetAppID(configuration);

            if (string.IsNullOrEmpty(appID))
            {
                SetConfigServerTokenComplete(configuration, serverToken, "Invalid App ID", onSetComplete);
                return;
            }
            // Set server token
            WitAuthUtility.SetAppServerToken(appID, serverToken);
            // Clear client token
            ApplyClientToken(configuration, string.Empty, null);
            // Find client id
            PerformConfigRequest(configuration, configuration.GetClientToken(appID), ApplyClientToken, (error) =>
            {
                SetConfigServerTokenComplete(configuration, serverToken, error, onSetComplete);
            });
        }
Пример #6
0
        private static void FetchApplicationFromServerToken(WitConfiguration configuration,
                                                            string serverToken, Action response)
        {
            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)
                        {
                            if (null != configuration.application)
                            {
                                configuration.application.UpdateData(applications[i]);
                            }
                            else
                            {
                                configuration.application =
                                    WitApplication.FromJson(applications[i]);
                            }

                            EditorForegroundRunner.Run(() =>
                            {
                                WitAuthUtility.SetAppServerToken(configuration.application.id,
                                                                 serverToken);
                                response?.Invoke();
                            });
                            break;
                        }
                    }
                }
                else
                {
                    Debug.LogError(r.StatusDescription);
                }
            };
            listRequest.Request();
        }
Пример #7
0
        public void Initialize()
        {
            // Refresh configuration & auth tokens
            configuration = target as WitConfiguration;

            // Get app server token
            _serverToken = WitAuthUtility.GetAppServerToken(configuration);
            if (CanConfigurationRefresh(configuration) && WitConfigurationUtility.IsServerTokenValid(_serverToken))
            {
                // Get client token if needed
                _appID = WitConfigurationUtility.GetAppID(configuration);
                if (string.IsNullOrEmpty(_appID))
                {
                    configuration.SetServerToken(_serverToken);
                }
                // Refresh additional data
                else
                {
                    SafeRefresh();
                }
            }
        }
Пример #8
0
        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());
        }
Пример #9
0
        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
        }
Пример #10
0
 protected override void OnEnable()
 {
     WitAuthUtility.InitEditorTokens();
     SetWitEditor();
     RefreshConfigList();
 }
Пример #11
0
        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();
        }
Пример #12
0
        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();
        }
Пример #13
0
        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());
        }
Пример #14
0
 // Token valid check
 public static bool IsServerTokenValid(string serverToken)
 {
     return(!string.IsNullOrEmpty(serverToken) && WitAuthUtility.IsServerTokenValid(serverToken));
 }