From f70a344a957e48094f7e813cbc84ce118aff99a1 Mon Sep 17 00:00:00 2001 From: "Matt Shim (TEKsystems)" Date: Thu, 30 Mar 2017 10:48:12 -0700 Subject: [PATCH] added blog examples to Node and Csharp --- CSharp/Blog-CustomChannelData/.gitattributes | 63 +++++ CSharp/Blog-CustomChannelData/.gitignore | 245 ++++++++++++++++++ .../App_Start/WebApiConfig.cs | 36 +++ .../Azure_Bot_Generic_CSharp.csproj | 181 +++++++++++++ .../Azure_Bot_Generic_CSharp.sln | 22 ++ .../Controllers/MessagesController.cs | 89 +++++++ .../Dialogs/ShareButtonDialog.cs | 54 ++++ CSharp/Blog-CustomChannelData/Global.asax | 1 + CSharp/Blog-CustomChannelData/Global.asax.cs | 17 ++ .../Models/FacebookAttachment.cs | 24 ++ .../Models/FacebookButton.cs | 36 +++ .../Models/FacebookButtonTemplate.cs | 32 +++ .../Models/FacebookChannelData.cs | 14 + .../Models/FacebookGenericTemplate.cs | 18 ++ .../Models/FacebookGenericTemplateContent.cs | 26 ++ .../Models/FacebookShareButton.cs | 21 ++ .../Properties/AssemblyInfo.cs | 35 +++ .../Blog-CustomChannelData/Web.Debug.config | 30 +++ .../Blog-CustomChannelData/Web.Release.config | 31 +++ CSharp/Blog-CustomChannelData/Web.config | 68 +++++ CSharp/Blog-CustomChannelData/default.htm | 12 + CSharp/Blog-CustomChannelData/packages.config | 15 ++ .../node_custom_channel.js | 80 ++++++ Node/blog-customChannelData/package.json | 35 +++ 24 files changed, 1185 insertions(+) create mode 100644 CSharp/Blog-CustomChannelData/.gitattributes create mode 100644 CSharp/Blog-CustomChannelData/.gitignore create mode 100644 CSharp/Blog-CustomChannelData/App_Start/WebApiConfig.cs create mode 100644 CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.csproj create mode 100644 CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.sln create mode 100644 CSharp/Blog-CustomChannelData/Controllers/MessagesController.cs create mode 100644 CSharp/Blog-CustomChannelData/Dialogs/ShareButtonDialog.cs create mode 100644 CSharp/Blog-CustomChannelData/Global.asax create mode 100644 CSharp/Blog-CustomChannelData/Global.asax.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookAttachment.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookButton.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookButtonTemplate.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookChannelData.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplate.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplateContent.cs create mode 100644 CSharp/Blog-CustomChannelData/Models/FacebookShareButton.cs create mode 100644 CSharp/Blog-CustomChannelData/Properties/AssemblyInfo.cs create mode 100644 CSharp/Blog-CustomChannelData/Web.Debug.config create mode 100644 CSharp/Blog-CustomChannelData/Web.Release.config create mode 100644 CSharp/Blog-CustomChannelData/Web.config create mode 100644 CSharp/Blog-CustomChannelData/default.htm create mode 100644 CSharp/Blog-CustomChannelData/packages.config create mode 100644 Node/blog-customChannelData/node_custom_channel.js create mode 100644 Node/blog-customChannelData/package.json diff --git a/CSharp/Blog-CustomChannelData/.gitattributes b/CSharp/Blog-CustomChannelData/.gitattributes new file mode 100644 index 0000000000..1ff0c42304 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/CSharp/Blog-CustomChannelData/.gitignore b/CSharp/Blog-CustomChannelData/.gitignore new file mode 100644 index 0000000000..3a2238d6bf --- /dev/null +++ b/CSharp/Blog-CustomChannelData/.gitignore @@ -0,0 +1,245 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/App_Start/WebApiConfig.cs b/CSharp/Blog-CustomChannelData/App_Start/WebApiConfig.cs new file mode 100644 index 0000000000..530014ffa8 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/App_Start/WebApiConfig.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Web.Http; + +namespace Azure_Bot_Generic_CSharp +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + // Json settings + config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; + config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented; + JsonConvert.DefaultSettings = () => new JsonSerializerSettings() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + Formatting = Newtonsoft.Json.Formatting.Indented, + NullValueHandling = NullValueHandling.Ignore, + }; + + // Web API configuration and services + + // Web API routes + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + } + } +} diff --git a/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.csproj b/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.csproj new file mode 100644 index 0000000000..cf22f26f86 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.csproj @@ -0,0 +1,181 @@ + + + + + Debug + AnyCPU + + + 2.0 + {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Azure_Bot_Generic_CSharp + Bot Application1 + v4.6 + true + + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll + True + + + ..\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll + True + + + ..\packages\Microsoft.Bot.Builder.3.0.0\lib\net46\Microsoft.Bot.Builder.dll + True + + + ..\packages\Microsoft.Bot.Builder.3.0.0\lib\net46\Microsoft.Bot.Connector.dll + True + + + + ..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + True + + + ..\packages\Microsoft.Rest.ClientRuntime.1.8.2\lib\net45\Microsoft.Rest.ClientRuntime.dll + True + + + ..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.1.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll + True + + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True + + + + ..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + + + + + + + + + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll + True + + + + + + + + + + + + Designer + + + + + + + Global.asax + + + + + + + + + + + + + + + + Web.config + + + Web.config + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + true + + + + + + + + + True + True + 3979 + / + http://localhost:3979/ + False + False + + + False + + + + + + \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.sln b/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.sln new file mode 100644 index 0000000000..b8b1d06dfe --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Azure_Bot_Generic_CSharp.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure_Bot_Generic_CSharp", "Azure_Bot_Generic_CSharp\Azure_Bot_Generic_CSharp.csproj", "{A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/CSharp/Blog-CustomChannelData/Controllers/MessagesController.cs b/CSharp/Blog-CustomChannelData/Controllers/MessagesController.cs new file mode 100644 index 0000000000..c5f2f1f344 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Controllers/MessagesController.cs @@ -0,0 +1,89 @@ +using System; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web.Http; +using System.Diagnostics; +using System.Web.Http.Description; +using Microsoft.Bot.Connector; +using Microsoft.Bot.Builder.Dialogs; +using Newtonsoft.Json; +//get facebook channel data models +using Azure_Bot_Generic_CSharp.Models; + +namespace Azure_Bot_Generic_CSharp +{ + [BotAuthentication] + public class MessagesController : ApiController + { + /// + /// POST: api/Messages + /// Receive a message from a user and reply to it + /// + public async Task Post([FromBody]Activity activity) + { + if (activity.Type == ActivityTypes.Message) + { + Trace.WriteLine("Got Message"); + Trace.WriteLine(activity.ToString()); + //create connector service + ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); + //check for a Facebook message here + if (activity.ChannelId == "facebook") + { + //send acknowledgement + Activity reply = activity.CreateReply("Facebook Messenger message detected! Beep boop. [o o]"); + await connector.Conversations.ReplyToActivityAsync(reply); + + //send to the share button dialog + await Conversation.SendAsync(activity, () => new ShareButtonDialog()); + } + else + { + // calculate something for us to return + int length = (activity.Text ?? string.Empty).Length; + + // return our reply to the user + Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters"); + await connector.Conversations.ReplyToActivityAsync(reply); + } + } + else + { + HandleSystemMessage(activity); + } + var response = Request.CreateResponse(HttpStatusCode.OK); + return response; + } + + private Activity HandleSystemMessage(Activity message) + { + if (message.Type == ActivityTypes.DeleteUserData) + { + // Implement user deletion here + // If we handle user deletion, return a real message + } + else if (message.Type == ActivityTypes.ConversationUpdate) + { + // Handle conversation state changes, like members being added and removed + // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info + // Not available in all channels + } + else if (message.Type == ActivityTypes.ContactRelationUpdate) + { + // Handle add/remove from contact lists + // Activity.From + Activity.Action represent what happened + } + else if (message.Type == ActivityTypes.Typing) + { + // Handle knowing tha the user is typing + } + else if (message.Type == ActivityTypes.Ping) + { + } + + return null; + } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Dialogs/ShareButtonDialog.cs b/CSharp/Blog-CustomChannelData/Dialogs/ShareButtonDialog.cs new file mode 100644 index 0000000000..e51b37dfd8 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Dialogs/ShareButtonDialog.cs @@ -0,0 +1,54 @@ +namespace Azure_Bot_Generic_CSharp +{ + using System; + using System.Diagnostics; + using System.Threading.Tasks; + using Microsoft.Bot.Connector; + using Microsoft.Bot.Builder.Dialogs; + using Models; + + [Serializable] + public class ShareButtonDialog : IDialog + { + public async Task StartAsync(IDialogContext context) + { + context.Wait(this.MessageReceivedAsync); + } + public async Task MessageReceivedAsync(IDialogContext context, IAwaitable argument) + { + var message = await argument; + + //create a reply message + var reply = context.MakeMessage(); + //create a channel data object to act as a facebook share button + reply.ChannelData = new FacebookChannelData() + { + Attachment = new FacebookAttachment() + { + Payload = new FacebookGenericTemplate() + { + Elements = new object[] + { + new FacebookGenericTemplateContent() + { + Buttons = new[] + { + new FacebookShareButton() + } + } + } + } + } + }; + + //send message + await context.PostAsync(reply); + + var reply2 = context.MakeMessage(); + reply2.Text = "This is a message after the Share Button template."; + await context.PostAsync(reply2); + //wait for more messages to be sent here + context.Wait(MessageReceivedAsync); + } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Global.asax b/CSharp/Blog-CustomChannelData/Global.asax new file mode 100644 index 0000000000..1f57e667ba --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="Azure_Bot_Generic_CSharp.WebApiApplication" Language="C#" %> diff --git a/CSharp/Blog-CustomChannelData/Global.asax.cs b/CSharp/Blog-CustomChannelData/Global.asax.cs new file mode 100644 index 0000000000..d329a5b120 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Global.asax.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Http; +using System.Web.Routing; + +namespace Azure_Bot_Generic_CSharp +{ + public class WebApiApplication : System.Web.HttpApplication + { + protected void Application_Start() + { + GlobalConfiguration.Configure(WebApiConfig.Register); + } + } +} diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookAttachment.cs b/CSharp/Blog-CustomChannelData/Models/FacebookAttachment.cs new file mode 100644 index 0000000000..207da2aee9 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookAttachment.cs @@ -0,0 +1,24 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookAttachment + { + public FacebookAttachment() + { + this.Type = "template"; + } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("payload")] + public dynamic Payload { get; set; } + + //make sure ToString converts the payload + public override string ToString() + { + return this.Payload.ToString(); + } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookButton.cs b/CSharp/Blog-CustomChannelData/Models/FacebookButton.cs new file mode 100644 index 0000000000..1d5e6fbedb --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookButton.cs @@ -0,0 +1,36 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookPostbackButton + { + public FacebookPostbackButton() + { + this.Type = "postback"; + this.Title = "Postback Title"; + this.Payload = "Postback Payload"; + } + + public FacebookPostbackButton(string title, string payload) + { + this.Type = "postback"; + this.Title = title; + this.Payload = payload; + } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("payload")] + public string Payload { get; set; } + + public override string ToString() + { + return $"type: {this.Type}"; + } + + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookButtonTemplate.cs b/CSharp/Blog-CustomChannelData/Models/FacebookButtonTemplate.cs new file mode 100644 index 0000000000..1c64dc357d --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookButtonTemplate.cs @@ -0,0 +1,32 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookButtonTemplate + { + public FacebookButtonTemplate() + { + this.TemplateType = "button"; + this.Text = "This is default text."; + } + public FacebookButtonTemplate(string text) + { + this.TemplateType = "button"; + this.Text = text; + } + + [JsonProperty("template_type")] + public string TemplateType { get; set; } + + [JsonProperty("text")] + public string Text { get; set; } + + [JsonProperty("buttons")] + public FacebookButton[] Buttons { get; set; } + + public override string ToString() + { + return $"template_type: {this.TemplateType}\ntext: {this.Text}\nbuttons:\n\t {this.Buttons}"; + } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookChannelData.cs b/CSharp/Blog-CustomChannelData/Models/FacebookChannelData.cs new file mode 100644 index 0000000000..1d3416b615 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookChannelData.cs @@ -0,0 +1,14 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookChannelData + { + [JsonProperty("attachment")] + public FacebookAttachment Attachment + { + get; + internal set; + } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplate.cs b/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplate.cs new file mode 100644 index 0000000000..e0aa4f0207 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplate.cs @@ -0,0 +1,18 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookGenericTemplate + { + public FacebookGenericTemplate() + { + this.TemplateType = "generic"; + } + + [JsonProperty("template_type")] + public string TemplateType { get; set; } + + [JsonProperty("elements")] + public object[] Elements { get; set; } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplateContent.cs b/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplateContent.cs new file mode 100644 index 0000000000..9f3ef0da4c --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookGenericTemplateContent.cs @@ -0,0 +1,26 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookGenericTemplateContent + { + public FacebookGenericTemplateContent() + { + this.Title = "This is a title."; + this.Subtitle = "This is a subtitle."; + this.ImageUrl = ""; + } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + + [JsonProperty("image_url")] + public string ImageUrl { get; set; } + + [JsonProperty("buttons")] + public object[] Buttons { get; set; } + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Models/FacebookShareButton.cs b/CSharp/Blog-CustomChannelData/Models/FacebookShareButton.cs new file mode 100644 index 0000000000..fdd2a9083a --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Models/FacebookShareButton.cs @@ -0,0 +1,21 @@ +namespace Azure_Bot_Generic_CSharp.Models +{ + using Newtonsoft.Json; + + public class FacebookShareButton + { + public FacebookShareButton() + { + this.Type = "element_share"; + } + + [JsonProperty("type")] + public string Type { get; set; } + + public override string ToString() + { + return $"type: {this.Type}"; + } + + } +} \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Properties/AssemblyInfo.cs b/CSharp/Blog-CustomChannelData/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..9ebb82c14b --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Azure_Bot_Generic_CSharp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Azure_Bot_Generic_CSharp")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a8ba1066-5695-4d71-abb4-65e5a5e0c3d4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CSharp/Blog-CustomChannelData/Web.Debug.config b/CSharp/Blog-CustomChannelData/Web.Debug.config new file mode 100644 index 0000000000..2e302f9f95 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Web.Release.config b/CSharp/Blog-CustomChannelData/Web.Release.config new file mode 100644 index 0000000000..c35844462b --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/Web.config b/CSharp/Blog-CustomChannelData/Web.config new file mode 100644 index 0000000000..05b292cffe --- /dev/null +++ b/CSharp/Blog-CustomChannelData/Web.config @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharp/Blog-CustomChannelData/default.htm b/CSharp/Blog-CustomChannelData/default.htm new file mode 100644 index 0000000000..85119b6fe1 --- /dev/null +++ b/CSharp/Blog-CustomChannelData/default.htm @@ -0,0 +1,12 @@ + + + + + + + +

Azure_Bot_Generic_CSharp

+

Describe your bot here and your terms of use etc.

+

Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to

https://your_bots_hostname/api/messages

+ + diff --git a/CSharp/Blog-CustomChannelData/packages.config b/CSharp/Blog-CustomChannelData/packages.config new file mode 100644 index 0000000000..9aa73aca2e --- /dev/null +++ b/CSharp/Blog-CustomChannelData/packages.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Node/blog-customChannelData/node_custom_channel.js b/Node/blog-customChannelData/node_custom_channel.js new file mode 100644 index 0000000000..68def93ff1 --- /dev/null +++ b/Node/blog-customChannelData/node_custom_channel.js @@ -0,0 +1,80 @@ +//loading modules +var express = require("express"); +var restify = require("restify"); +var botbuilder = require("botbuilder"); +var request = require("request-promise"); + +//load environment variables here +const MSFT_APP_ID = process.env.MSFT_APP_ID; +const MSFT_APP_PW = process.env.MSFT_APP_PW; + +//create an express server +var app = express(); +app.listen( process.env.PORT || 3000, function(){ + console.log("Express app listening on port: " + process.env.PORT || 3000); +}); + +//create a chat connector for the bot +var connector = new botbuilder.ChatConnector({ + appId: MSFT_APP_ID, + appPassword: MSFT_APP_PW +}); + +//load the botbuilder classes and build a unversal bot using the chat connector +var bot = new botbuilder.UniversalBot(connector); + +//hook up bot endpoint +app.post("/messages/receive", connector.listen()); + +//root dialog +bot.dialog("/", function(session){ + + console.log("-------------------------------------------------"); + console.log("Bot Received Message at '/' dialogue endpoint: "); + + //detect Facebook Messenger message here + if(session.message.address.channelId == "facebook"){ + session.send("Facebook message recognized!"); + session.beginDialog("/send_share_button"); + } else session.send("Channel other than Facebook recognized."); + +}); + +//where we create a facebook share button using sourceEvent +bot.dialog("/send_share_button", function(session){ + //construct a new message with the current session context + var msg = new botbuilder.Message(session).sourceEvent({ + //specify the channel + facebook: { + //format according to channel's requirements + //(in our case, the above JSON required by Facebook) + attachment: { + type: "template", + payload: { + template_type: "generic", + elements: [ + { + title: "Microsoft Bot Framework", + subtitle: "Check it out!", + buttons: [ + { + type: "web_url", + url: "https://dev.botframework.com", + title: "Go to Dev Portal" + }, + { + //this is our share button + type: "element_share" + } + ] + } + ] + } + } //end of attachment + } + }); + + //send message + session.send(msg); + session.endDialog("Show your friends!"); +}); diff --git a/Node/blog-customChannelData/package.json b/Node/blog-customChannelData/package.json new file mode 100644 index 0000000000..c9516e5d29 --- /dev/null +++ b/Node/blog-customChannelData/package.json @@ -0,0 +1,35 @@ +{ + "name": "azure_node_bot", + "version": "1.0.0", + "description": "Microsoft Bot Framework bot written in NodeJS to test issues.", + "main": "node_bot.js", + "dependencies": { + "botbuilder": "^3.7.0", + "express": "^4.14.1", + "request-promise": "^4.1.1", + "restify": "^4.3.0" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node node_bot.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Fignewton5/AzureNodeBot.git" + }, + "keywords": [ + "Microsoft", + "Bot", + "Framework", + "Chatbot", + "Chat", + "Bot" + ], + "author": "Tony Anziano", + "license": "ISC", + "bugs": { + "url": "https://github.com/Fignewton5/AzureNodeBot/issues" + }, + "homepage": "https://github.com/Fignewton5/AzureNodeBot#readme" +}