diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/FacebookMessengerController.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/FacebookMessengerController.cs deleted file mode 100644 index 8545f3a5..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/FacebookMessengerController.cs +++ /dev/null @@ -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().FirstOrDefault(x => x.AgentId == agentId && x.Platform == "Facebook Messenger"); - - return config.VerifyToken == token ? Ok(challenge) : Ok(agentId); - } - - return BadRequest(); - } - - [HttpPost("{agentId}")] - public async Task 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(json); - } - - body.Entry.ForEach(entry => - { - entry.Messaging.ForEach(msg => - { - // received text message - if (msg.Message.ContainsKey("text")) - { - OnTextMessaged(agentId, new WebhookMessage - { - Sender = msg.Sender, - Recipient = msg.Recipient, - Timestamp = msg.Timestamp, - Message = msg.Message.ToObject() - }); - } - }); - - }); - - return Ok(); - } - - private void OnTextMessaged(string agentId, WebhookMessage 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().FirstOrDefault(x => x.AgentId == agentId && x.Platform == "Facebook Messenger"); - - SendTextMessage(config.AccessToken, new WebhookMessage - { - Recipient = message.Sender.ToObject(), - Message = new WebhookTextMessage - { - Text = String.IsNullOrEmpty(aiResponse.Result.Fulfillment.Speech) ? aiResponse.Result.Action : aiResponse.Result.Fulfillment.Speech - } - });*/ - } - - private void SendTextMessage(string accessToken, WebhookMessage 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); - } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/IWebhookMessageBody.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/IWebhookMessageBody.cs deleted file mode 100644 index 20e97b01..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/IWebhookMessageBody.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BotSharp.RestApi.Integrations.FacebookMessenger -{ - public interface IWebhookMessageBody - { - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEvent.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEvent.cs deleted file mode 100644 index 86dd445a..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEvent.cs +++ /dev/null @@ -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 Entry { get; set; } - } - - -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEventEntry.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEventEntry.cs deleted file mode 100644 index ab1cadd1..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookEventEntry.cs +++ /dev/null @@ -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 Messaging { get; set; } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessage.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessage.cs deleted file mode 100644 index 7dfd387b..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessage.cs +++ /dev/null @@ -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 where TWebhookMessage : IWebhookMessageBody - { - public WebhookMessageSender Sender { get; set; } - - public WebhookMessageRecipient Recipient { get; set; } - - public long Timestamp { get; set; } - - public TWebhookMessage Message { get; set; } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageQuickReply.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageQuickReply.cs deleted file mode 100644 index 9abccb34..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageQuickReply.cs +++ /dev/null @@ -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; } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageRecipient.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageRecipient.cs deleted file mode 100644 index ecea618e..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageRecipient.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BotSharp.RestApi.Integrations.FacebookMessenger -{ - public class WebhookMessageRecipient - { - /// - /// PAGE_ID - /// - public String Id { get; set; } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageSender.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageSender.cs deleted file mode 100644 index ea1b37ad..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookMessageSender.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BotSharp.RestApi.Integrations.FacebookMessenger -{ - public class WebhookMessageSender - { - /// - /// PSID - /// - public String Id { get; set; } - } -} diff --git a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookTextMessage.cs b/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookTextMessage.cs deleted file mode 100644 index b7e8b1d3..00000000 --- a/BotSharp.RestApi/Integrations/FacebookMessenger/WebhookTextMessage.cs +++ /dev/null @@ -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; } - } -} diff --git a/BotSharp.sln b/BotSharp.sln index 27dc9a6b..d0608062 100644 --- a/BotSharp.sln +++ b/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 diff --git a/README.rst b/README.rst index c23e9bcd..675827c6 100644 --- a/README.rst +++ b/README.rst @@ -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`_ diff --git a/README_zh.rst b/README_zh.rst index cb4bda67..2677ebb6 100644 --- a/README_zh.rst +++ b/README_zh.rst @@ -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