如何在bot messenger频道中抓取facebook的用户名

时间:2017-04-26 13:40:15

标签: visual-studio bots dialogflow asp.net-webhooks

我想在facebook messenger频道的机器人中捕获facebook用户的用户名。我想在欢迎消息中使用此数据,所以我想发送消息:欢迎{username}到我们的机器人! 。

如果用户是新条目我想显示帮助菜单(如何使用机器人)...如果用户重新进入机器人..我想显示:欢迎回来{username}然后标准菜单。

对于我的机器人我使用api.ai和webhook我使用visual studio 2015 c#。

对于这个机器人我创建了一个webhook控制器,对于某些操作我有一些代码......

在同一个文件中,我必须为welcome.input

创建另一个操作

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;
    }
}


}

}

您可以在我的webhook中帮助我添加//添加代码吗?

0 个答案:

没有答案