Beispiel #1
0
        /// <summary>
        /// Resets the specified session.
        /// </summary>
        /// <param name="session">The name of the session to reset.</param>
        private IEnumerator ClearSessionRequest(string session)
        {
            // Gets the JWT access token.
            string accessToken = string.Empty;

            while (!JwtCache.TryGetToken(accessSettings.ServiceAccount, out accessToken))
            {
                yield return(JwtCache.GetToken(accessSettings.CredentialsFileName,
                                               accessSettings.ServiceAccount));
            }

            string url = string.Format(
                "https://dialogflow.googleapis.com/v2/projects/{0}/agent/sessions/{1}/contexts",
                accessSettings.ProjectId, session);
            UnityWebRequest deleteRequest = new UnityWebRequest(url);

            deleteRequest.method = "DELETE";
            deleteRequest.SetRequestHeader("Authorization", "Bearer " + accessToken);
            deleteRequest.SetRequestHeader("Content-Type", "application/json");
            yield return(deleteRequest.SendWebRequest());

            if (deleteRequest.isHttpError || deleteRequest.isNetworkError)
            {
                Debug.LogError(deleteRequest.responseCode + ": " + deleteRequest.error);
            }
            else
            {
                SessionCleared?.Invoke(session);
            }
        }
Beispiel #2
0
 protected void OnSessionCleared(EventArgs e) => SessionCleared?.Invoke(this, e);