我正在使用api.ai和webhook visual studo 2015 c#。如何在c中使用webhook獲取用戶信息#
我爲某些意圖創建了一些操作,現在我正在尋找名爲「welcome.input」的操作。我想獲取用戶的用戶名。 如果用戶第一次開始與機器人進行對話,我想給他提供查看幫助菜單或標準菜單的可能性, 並且當用戶在機器人中重新輸入時我想發送文本:歡迎回來{用戶名}並向他展示標準菜單。
你有什麼想法如何做到這一點。
我正在閱讀https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-State這個例子......但我不能在我的項目中作爲webhook添加適配。
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using WebhookReceiver.Models;
namespace FBReceiver.Controllers
{
public class facebookController : ApiController
{
public string Get()
{
return "OK";
}
public int Get(int id)
{
return id;
}
public ApiAiResponse Post([FromBody]JObject jsonRequest)
{
using (FbReceiverModelDataContext ctx = new
FbModelDataContext())
{
ctx.spTblTransactions_CreateNew("xyz", "Request",
jsonRequest.ToString(), HttpContext.Current.User.Identity.Name);
ApiAiRequest request = jsonRequest.ToObject<ApiAiRequest>();
ApiAiResponse response = new ApiAiResponse();
JObject jObject = JObject.Parse(request.result.parameters.ToString());
string xyznumber = (string)jObject["xyznumber"] != null ? (string)jObject["xyznumber"] : "";
string otherparameter = (string)jObject["otherparameter"] != null ? (string)jObject["otherparameter"] : "";
if (("action1".Equals(request.result.action.ToLower())))
{
tbla a= new tbla();
a= ctx.tblAa.SingleOrDefault(u => u.a.ToLower() == a.ToLower());
if (a!= null)
{
response.speech = "a with number " + xyznumber+ " " + a.aaaa;
response.source = "aaa";
}
else if (!string.IsNullOrEmpty(xyznumber))
{
response.speech = "Generic info about " + xyznumber;
response.displayText = "Generic info about " + xyznumber;
response.source = "aaaa";
}
else
{
response.speech = "No info";
response.displayText = "No info";
response.source = "Parcels";
}
}
else if (("pay.info".Equals(request.result.action.ToLower())))
{
///yyyyyyyyyyyyyyyyyyyyyyyyyyyyy
}
else if (("welcome.input".Equals(request.result.action.ToLower())))
{
// to do
}
else
{
response.speech = "something is wrong ????";
response.displayText = "something is wrong ????";
response.source = "None";
}
ctx.spTblTransactions_CreateNew("aaaa", "Response", JsonConvert.SerializeObject(response), HttpContext.Current.User.Identity.Name);
return response;
}
}
}
}
請幫幫我。我曾多次尋找關於這個話題
目前還不清楚有什麼問題。你使用bot框架嗎?爲什麼你不能使用註釋的代碼? –
我使用Api.ai和webhook我使用visual studio 2015,C#。評論的代碼是不好的...我想你的幫助確實得到用戶bot的用戶名,並在消息中使用它 – user2454923
所以你沒有使用bot框架?仍然不清楚。代碼在哪裏運行?如果它不是一個殭屍框架的問題,請刪除標籤 –