LoginSignup
0
1

More than 5 years have passed since last update.

DialogflowのUnity SDKはiOSで動かない

Posted at

はじめに

タイトルの通りです。Assetstoreのレビューにも書いてありますが、iOSでは動きません。Editorだと大丈夫なんですが。スレッド関係のエラーのように見えますが、どうやって直して良いかわかりません。

どうするか

REST APIを自分で叩いた方が良さそうです。自分はBest HTTP(Pro edition)を使ってます。他のアセットも試しましたが、一番ストレスなく使えるのはこれでした。iOSでも安定して動作します。

capture.jpeg

サンプルコードはこんな感じです。

TestBestHTTP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BestHTTP;

public class TestBestHTTP : MonoBehaviour {

    public void OnClick(){
        HTTPRequest request = new HTTPRequest(new System.Uri("https://api.dialogflow.com/v1/query?v=20150910&lang=ja&query=声調の勉強&sessionId=12345&timezone=Asia/Tokyo"), OnRequestFinished); 
        request.AddHeader("Authorization", "Bearer c***f");
        request.Send();    
    }

    void OnRequestFinished(HTTPRequest request, HTTPResponse response)
    {
        Debug.Log("Request Finished! Text received: " + response.DataAsText);
    }
}

Headerに"Authorization"として"Bearer Client access token"が必要です。Client access tokenはDialogflowのエージェントの設定画面から取ってきます。

c.png

あと、URLにv=...でバージョンを入れる必要があります。これらについてはここを参照。言語(lang)とsessionIDも指定します。

すると、JSON形式でレスポンスが返ってきます。

{
  "id": "4*****8",
  "timestamp": "2017-11-15T09:42:31.482Z",
  "lang": "ja",
  "result": {
    "source": "agent",
    "resolvedQuery": "声調の勉強",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "Tones": "声調"
    },
    "contexts": [],
    "metadata": {
      "intentId": "6*******e",
      "webhookUsed": "false",
      "webhookForSlotFillingUsed": "false",
      "intentName": "L*****h"
    },
    "fulfillment": {
      "speech": "<speak> <audio src=\"h******** </speak>",
      "messages": [
        {
          "type": 0,
          "speech": "<speak>\n<audio src=\"h*****</speak>"
        }
      ]
    },
    "score": 1.0
  },
  "status": {
    "code": 200,
    "errorType": "success",
    "webhookTimedOut": false
  },
  "sessionId": "12345"
}

一つ一つの意味についてはこちらを参照。

終わりに

公式のSDKでiOSにして欲しいですが、デベロッパーさんのアクティビティがだいぶ低いようなので望み薄です。自分でなんとかした方が良さそうです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1