remove facebook messenger.
This commit is contained in:
parent
7b21b6ab8f
commit
f230076cda
|
|
@ -1,117 +0,0 @@
|
|||
using BotSharp.Core.Engines;
|
||||
using BotSharp.NLP;
|
||||
using BotSharp.Platform.Models;
|
||||
using BotSharp.RestApi.Integrations.FacebookMessenger;
|
||||
using DotNetToolkit;
|
||||
using EntityFrameworkCore.BootKit;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations
|
||||
{
|
||||
[Route("v1/[controller]")]
|
||||
public class FacebookMessengerController : ControllerBase
|
||||
{
|
||||
[HttpGet("{agentId}")]
|
||||
public ActionResult Verify([FromRoute] string agentId)
|
||||
{
|
||||
var mode = Request.Query.ContainsKey("hub.mode") ? Request.Query["hub.mode"].ToString() : String.Empty;
|
||||
var token = Request.Query.ContainsKey("hub.verify_token") ? Request.Query["hub.verify_token"].ToString() : String.Empty;
|
||||
var challenge = Request.Query.ContainsKey("hub.challenge") ? Request.Query["hub.challenge"].ToString() : String.Empty;
|
||||
|
||||
if (mode == "subscribe")
|
||||
{
|
||||
var dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||
var config = dc.Table<AgentIntegration>().FirstOrDefault(x => x.AgentId == agentId && x.Platform == "Facebook Messenger");
|
||||
|
||||
return config.VerifyToken == token ? Ok(challenge) : Ok(agentId);
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpPost("{agentId}")]
|
||||
public async Task<ActionResult> CallbackAsync([FromRoute] string agentId)
|
||||
{
|
||||
WebhookEvent body;
|
||||
IWebhookMessageBody response = null;
|
||||
|
||||
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
|
||||
{
|
||||
var json = await reader.ReadToEndAsync();
|
||||
body = JsonConvert.DeserializeObject<WebhookEvent>(json);
|
||||
}
|
||||
|
||||
body.Entry.ForEach(entry =>
|
||||
{
|
||||
entry.Messaging.ForEach(msg =>
|
||||
{
|
||||
// received text message
|
||||
if (msg.Message.ContainsKey("text"))
|
||||
{
|
||||
OnTextMessaged(agentId, new WebhookMessage<WebhookTextMessage>
|
||||
{
|
||||
Sender = msg.Sender,
|
||||
Recipient = msg.Recipient,
|
||||
Timestamp = msg.Timestamp,
|
||||
Message = msg.Message.ToObject<WebhookTextMessage>()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private void OnTextMessaged(string agentId, WebhookMessage<WebhookTextMessage> message)
|
||||
{
|
||||
Console.WriteLine($"OnTextMessaged: {message.Message.Text}");
|
||||
|
||||
/*var ai = new ApiAi();
|
||||
var agent = ai.LoadAgent(agentId);
|
||||
ai.AiConfig = new AIConfiguration(agent.ClientAccessToken, SupportedLanguage.English) { AgentId = agentId };
|
||||
ai.AiConfig.SessionId = message.Sender.Id;
|
||||
var aiResponse = ai.TextRequest(new AIRequest { Query = new String[] { message.Message.Text } });
|
||||
|
||||
var dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||
var config = dc.Table<AgentIntegration>().FirstOrDefault(x => x.AgentId == agentId && x.Platform == "Facebook Messenger");
|
||||
|
||||
SendTextMessage(config.AccessToken, new WebhookMessage<WebhookTextMessage>
|
||||
{
|
||||
Recipient = message.Sender.ToObject<WebhookMessageRecipient>(),
|
||||
Message = new WebhookTextMessage
|
||||
{
|
||||
Text = String.IsNullOrEmpty(aiResponse.Result.Fulfillment.Speech) ? aiResponse.Result.Action : aiResponse.Result.Fulfillment.Speech
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private void SendTextMessage(string accessToken, WebhookMessage<WebhookTextMessage> body)
|
||||
{
|
||||
var client = new RestClient("https://graph.facebook.com");
|
||||
|
||||
var rest = new RestRequest("v2.6/me/messages", Method.POST);
|
||||
string json = JsonConvert.SerializeObject(body,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
});
|
||||
|
||||
rest.AddParameter("application/json", json, ParameterType.RequestBody);
|
||||
rest.AddQueryParameter("access_token", accessToken);
|
||||
|
||||
var response = client.Execute(rest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public interface IWebhookMessageBody
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookEvent
|
||||
{
|
||||
public string Object { get; set; }
|
||||
public List<WebhookEventEntry> Entry { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookEventEntry
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public long Time { get; set; }
|
||||
public List<WebhookMessage> Messaging { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookMessage
|
||||
{
|
||||
public WebhookMessageSender Sender { get; set; }
|
||||
|
||||
public WebhookMessageRecipient Recipient { get; set; }
|
||||
|
||||
public long Timestamp { get; set; }
|
||||
|
||||
public JObject Message { get; set; }
|
||||
}
|
||||
|
||||
public class WebhookMessage<TWebhookMessage> where TWebhookMessage : IWebhookMessageBody
|
||||
{
|
||||
public WebhookMessageSender Sender { get; set; }
|
||||
|
||||
public WebhookMessageRecipient Recipient { get; set; }
|
||||
|
||||
public long Timestamp { get; set; }
|
||||
|
||||
public TWebhookMessage Message { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookMessageQuickReply
|
||||
{
|
||||
public String Payload { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookMessageRecipient
|
||||
{
|
||||
/// <summary>
|
||||
/// PAGE_ID
|
||||
/// </summary>
|
||||
public String Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookMessageSender
|
||||
{
|
||||
/// <summary>
|
||||
/// PSID
|
||||
/// </summary>
|
||||
public String Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Integrations.FacebookMessenger
|
||||
{
|
||||
public class WebhookTextMessage : IWebhookMessageBody
|
||||
{
|
||||
public string Mid { get; set; }
|
||||
public String Text { get; set; }
|
||||
[JsonProperty("quick_reply")]
|
||||
public WebhookMessageQuickReply QuickReply { get; set; }
|
||||
}
|
||||
}
|
||||
40
BotSharp.sln
40
BotSharp.sln
|
|
@ -24,9 +24,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models",
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Dialogflow", "..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj", "{3599EC12-BE49-4BA2-B02F-86602BC1240C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "..\botsharp-rasa\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj", "{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Articulate", "..\botsharp-articulate\BotSharp.Platform.Articulate\BotSharp.Platform.Articulate.csproj", "{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Channel.FacebookMessenger", "..\botsharp-channel-fbmessenger\BotSharp.Channel.FacebookMessenger\BotSharp.Channel.FacebookMessenger.csproj", "{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
@ -134,30 +132,18 @@ Global
|
|||
{3599EC12-BE49-4BA2-B02F-86602BC1240C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3599EC12-BE49-4BA2-B02F-86602BC1240C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{3599EC12-BE49-4BA2-B02F-86602BC1240C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{3DE700F6-16AE-4A14-9119-E72BFBE85AB0}.Release|x64.Build.0 = Release|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{ED94ADD1-B8BA-4103-ABF9-662B19E450DD}.Release|x64.Build.0 = Release|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{BDAEF806-D1B0-479E-AAF6-21252E3FA3CE}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Extension Libraries
|
|||
BotSharp uses component design, the kernel is kept to a minimum, and business functions are implemented by external components. The modular design also allows contributors to better participate.
|
||||
|
||||
* BotSharp platform emulator extension which is compatible with RASA NLU. `botsharp-rasa`_
|
||||
* BotSharp platform extension which is compatible with Google Dialogflow. `botsharp-dialogflow`_
|
||||
* BotSharp platform emulator extension which is compatible with Google Dialogflow. `botsharp-dialogflow`_
|
||||
* BotSharp platform emulator extension which is compatible with Articulate AI. `botsharp-articulate`_
|
||||
* A channel module of BotSharp for Facebook Messenger. `botsharp-channel-fbmessenger`_
|
||||
* A channel module of BotSharp for Tencent Weixin. `botsharp-channel-weixin`_
|
||||
|
|
|
|||
|
|
@ -57,6 +57,15 @@ You can use docker compose to run BotSharp quickly, make sure you've got `Docker
|
|||
|
||||
Point your web browser at http://localhost:3000 and enjoy BotSharp with Articulate-UI.
|
||||
|
||||
Extension Libraries
|
||||
-----------------
|
||||
BotSharp uses component design, the kernel is kept to a minimum, and business functions are implemented by external components. The modular design also allows contributors to better participate.
|
||||
|
||||
* BotSharp platform emulator extension which is compatible with RASA NLU. `botsharp-rasa`_
|
||||
* BotSharp platform emulator extension which is compatible with Google Dialogflow. `botsharp-dialogflow`_
|
||||
* BotSharp platform emulator extension which is compatible with Articulate AI. `botsharp-articulate`_
|
||||
* A channel module of BotSharp for Facebook Messenger. `botsharp-channel-fbmessenger`_
|
||||
* A channel module of BotSharp for Tencent Weixin. `botsharp-channel-weixin`_
|
||||
|
||||
Documents
|
||||
---------
|
||||
|
|
@ -81,4 +90,9 @@ Scan to join group in Wechat
|
|||
.. _gitter: https://gitter.im/botsharpcore/Lobby
|
||||
.. _license: https://raw.githubusercontent.com/Oceania2018/BotSharp/master/LICENSE
|
||||
.. _botsharpnuget: https://www.nuget.org/packages/BotSharp.Core
|
||||
.. _botsharp-rasa: https://github.com/Oceania2018/botsharp-rasa
|
||||
.. _botsharp-dialogflow: https://github.com/Oceania2018/botsharp-dialogflow
|
||||
.. _botsharp-articulate: https://github.com/Oceania2018/botsharp-articulate
|
||||
.. _botsharp-channel-fbmessenger: https://github.com/Oceania2018/botsharp-channel-fbmessenger
|
||||
.. _botsharp-channel-weixin: https://github.com/Oceania2018/botsharp-channel-weixin
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue