【发布时间】:2017-09-22 09:38:48
【问题描述】:
我正在使用 api.ai 和 webhook visual studo 2015 c#。
我已经为一些意图创建了一些动作,现在我正在寻找一个名为“welcome.input”的动作。我想获取用户的用户名。 如果用户第一次开始与机器人对话,我想让他可以查看帮助菜单或标准菜单, 当用户重新进入机器人时,我想发送文本:欢迎回来 {username} 并向他展示标准菜单。
你知道怎么做吗?
我正在阅读 https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-State 这个示例……但我无法在我的项目中添加 apt 作为 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;
}
}
}
}
请帮帮我。这个话题我搜索了很多次
【问题讨论】:
-
不清楚是什么问题。你在使用机器人框架吗?为什么不能使用注释代码?
-
我使用的是 Api.ai,而对于 webhook,我使用的是 Visual Studio 2015,c#。注释代码不正确...我希望您的帮助获取用户机器人的用户名并在消息中使用它
-
所以你没有使用bot框架?还是不清楚。该代码在哪里运行?如果不是机器人框架问题,请删除标签
-
我同意,这看起来更像是“如何构建 webhook 架构”以在用户和机器人之间进行通信,而不是机器人框架问题
标签: c# facebook bots webhooks dialogflow-es