2016-11-22 6 views
0

.Netサーバーでボットアクションを実装する方法を教えてもらえますか? .netのためのテンプレートまたはliblaryがありますか?どうもありがとう。.Netサーバーでwit.aiアクションを実装する

+0

チェックこの1:https://github.com/valencianok/Wit.ai.net – ssakash

+0

あなたは、 "NETサーバー" とはどういう意味ですか? .NETで書かれたサービスがありますか? –

答えて

0

https://github.com/valencianok/Wit.ai.net

以下この溶液をWit.ai.net nugetパッケージに基づいており、アクションなどの会話を処理するための.NETライブラリがあります。

まずセットアップにマージするためのいくつかのハンドラを必要とする、停止、アクションは、セイ:

static object ActionHandler(string conversationId, object context, string action, Dictionary<string, List<Entity>> entities, double confidence) 
    { 
     Console.WriteLine("Action handler called"); 

     //Invoke correct action based on action name passed in by action parameter 
     Actions[action].Invoke(); 
     return context; 
    } 

    static object MergeHandler(string conversationId, object context, Dictionary<string, List<Entity>> entities, double confidence) 
    { 
     Console.WriteLine("Merge handler called"); 
     return context; 
    } 

    static void SayHandler(string conversationId, object context, string msg, double confidence) 
    { 
     Console.WriteLine("Say handler called " + msg); 
    } 

    static object StopHandler(string conversationId, object context) 
    { 
     Console.WriteLine("Stop handler called"); 
     return context; 
    } 

のActionHandlerあなたはウィットから渡されたアクションを聞きたい場合は、あなたがでinterrestedされているものです。 「action」パラメータは、実行するアクションを指示します。これらは、例えば、キーがアクション名であり、値がアクションである辞書で設定することができる。例:

//Define actions to run based on Wit callback 
    static void Action1() 
    { 
     Console.WriteLine("Action1 is called"); 
    } 
    static void Action2() 
    { 
     Console.WriteLine("Action2 is called"); 
    } 

    //Define actions in dictionary, key will be the action recieved from Wit response, value will be an invokable action 
    static Dictionary<string, Action> Actions => new Dictionary<string, Action> 
    { 
     { "action1", Action1 }, 
     { "action2", Action2 } 
    }; 

注:Wit.aiでアクションを持っている必要がありますが、この作業をするためにアクション1またはアクション2と呼ばれます。あなたがWit.aiにgetNewsアクションを持っているならば、例えば "getNews"に変更してください。

あなたは、その後の会話を作成し、会話にハンドラを渡す:

var conversation = new WitConversation<object>(WIT_ACCESS_TOKEN, "conversation-id-123", null, MergeHandler, SayHandler, ActionHandler, StopHandler); 

次に、あなただけの会話を開始:あなたが戻っていくつかのコンテキストキーを送信する必要がある場合

conversation.SendMessageAsync("Message to bot here").Result; 

をbotの場合は、任意のハンドラでcontextパラメータを変更して新しいコンテキストを返す必要があります。例えば、

static object ActionHandler(string conversationId, object context, string action, Dictionary<string, List<Entity>> entities, double confidence) 
{ 
    Console.WriteLine("Action handler called"); 

    //Invoke correct action based on action name passed in by action parameter 
    Actions[action].Invoke(); 
    return new { context_key_here = "context key value" }; 
} 

もちろん、この操作を行う簡単な方法の1つで、正しい方向に向けることを願っています。

また、すべてのWitアクションのインターフェイスを調整し、ActionHandler内で必要なアクションのインスタンスを取得することもできます。

以下のGistのコンソールアプリケーションでWit.ai apiから返されたアクションを簡単に実装しました。それが役に立てば幸い。

https://gist.github.com/SimonPirre/c2f571c4b47d0ac3defb1bc7292f456f

関連する問題