/// <summary> /// Contruce a result set based on the JSON response from the LUIS service. /// </summary> /// <param name="client">The client of which we can use to Reply</param> /// <param name="result">The parsed JSON from the LUIS service.</param> public LuisResult(LuisClient client, JToken result) { var luisResult = this; this.Reply = new Func <string, LuisResult>((text) => client.Reply(luisResult, text).GetAwaiter().GetResult()); Load(result); }
/// <summary> /// Set up a new instance of an <see cref="IntentRouter"/> using <see cref="IntentHandlerAttribute"/> flagged methods to handle the intents. /// </summary> /// <typeparam name="T">Type of handler</typeparam> /// <param name="client">The instance of the LuisClient to use</param> /// <param name="contextObject">The instance of the class that contains the flagged member functions to execute for each intent</param> /// <returns>A new instance of an <see cref="IntentRouter"/> that has registered intent handlers.</returns> public static IntentRouter Setup(LuisClient client, object contextObject) { var router = new IntentRouter(client); try { router.RegisterHandler(contextObject); } catch { router.Dispose(); throw; } return(router); }
/// <summary> /// Set up a new instance of an <see cref="IntentRouter"/> using <see cref="IntentHandlerAttribute"/> flagged methods in <typeparamref name="T"/> to handle the intents. /// </summary> /// <typeparam name="T">Type of handler</typeparam> /// <param name="client">The instance of the LuisClient to use</param> /// <returns>A new instance of an <see cref="IntentRouter"/> that has registered intent handlers.</returns> public static IntentRouter Setup <T>(LuisClient client) { var router = new IntentRouter(client); try { router.RegisterHandler <T>(); } catch { router.Dispose(); throw; } return(router); }
public IHttpActionResult POST() { try { //設定ChannelAccessToken(或抓取Web.Config) this.ChannelAccessToken = "qw6hghZir3I1lTq2PQCZ5Ap30I3eDEUju5UXCeS1E1vi8ja2QftluqLEf+TyAfmaS6CDLava+i1jzHEpy9rVVfxXz00kL615WL0mNasRf+Ge9pnxLv2sEmhg9Ml7AGT5MsqM7TktOmovad2CB8H4bgdB04t89/1O/w1cDnyilFU="; const string LuisAppId = "c8a36302-0cc4-426d-b4ba-cac8234a0f09"; const string LuisAppKey = "7d43e486a4fd49fe8e743470b8e5e8c6"; const string Luisdomain = "westus"; Microsoft.Cognitive.LUIS.LuisClient lc = new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain); //取得Line Event var item = this.ReceivedMessage.events.FirstOrDefault(); string Message = ""; //回覆訊息 switch (item.type) { case "join": Message = $"有人把我加入{item.source.type}中了,大家好啊~"; //回覆用戶 isRock.LineBot.Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, Message, ChannelAccessToken); break; case "message": if (item.message.text == "bye") { //回覆用戶 isRock.LineBot.Utility.ReplyMessage(item.replyToken, "bye-bye", ChannelAccessToken); //離開 if (item.source.type.ToLower() == "room") { isRock.LineBot.Utility.LeaveRoom(item.source.roomId, ChannelAccessToken); } if (item.source.type.ToLower() == "group") { isRock.LineBot.Utility.LeaveGroup(item.source.roomId, ChannelAccessToken); } } else if (item.message.text == "ID" || item.message.text == "id") { Message = "你的user id: " + Convert.ToString(item.source.userId); } else { var ret = lc.Predict(item.message.text).Result; if (ret.TopScoringIntent.Name == "打招呼") { Message = "你好啊!!!"; } else if (ret.TopScoringIntent.Name == "時間") { Message = "現在時間 : " + System.DateTime.Now; } else { Message = "??"; } } //回覆用戶 isRock.LineBot.Utility.ReplyMessage(item.replyToken, Message, ChannelAccessToken); break; default: break; } //response OK return(Ok()); } catch (Exception ex) { //回覆訊息 this.PushMessage("Ued3ad06f07d7d541a9cc742c7f2dcb5c", "發生錯誤:\n" + ex.Message); //response OK return(Ok()); } }
/// <summary> /// Constructs an <see cref="IntentRouter"/> using an existing LUIS client /// </summary> /// <param name="client">The instance of the LuisClient to use</param> public IntentRouter(LuisClient client) { _client = client; }
/// <summary> /// Constructs an <see cref="IntentRouter"/> using an appID and appKey /// </summary> /// <param name="appId">The application ID of the LUIS application</param> /// <param name="appKey">The application subscription key of the LUIS application</param> /// <param name="preview">A flag indicating whether to use preview features or not (Dialogue)</param> public IntentRouter(string appId, string appKey, bool preview = true) { _client = new LuisClient(appId, appKey, preview); }