├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS └── ISSUE_TEMPLATE │ ├── -net-directline-bug.md │ ├── -net-directline-feature-request.md │ └── -net-directline-question.md ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── build ├── 35MSSharedLib1024.snk └── ExtractCompressNuGet.ps1 ├── libraries ├── ActionTypes.cs ├── ActivityEx.cs ├── ActivityTypes.cs ├── Client │ ├── Conversations.cs │ ├── ConversationsExtensions.cs │ ├── DirectLineClient.cs │ ├── IConversations.cs │ ├── IDirectLineClient.cs │ ├── ITokens.cs │ ├── Models │ │ ├── Activity.cs │ │ ├── ActivitySet.cs │ │ ├── AnimationCard.cs │ │ ├── Attachment.cs │ │ ├── AudioCard.cs │ │ ├── CardAction.cs │ │ ├── CardImage.cs │ │ ├── ChannelAccount.cs │ │ ├── Conversation.cs │ │ ├── ConversationAccount.cs │ │ ├── ConversationReference.cs │ │ ├── Entity.cs │ │ ├── Error.cs │ │ ├── ErrorResponse.cs │ │ ├── Fact.cs │ │ ├── GeoCoordinates.cs │ │ ├── HeroCard.cs │ │ ├── MediaUrl.cs │ │ ├── Mention.cs │ │ ├── Place.cs │ │ ├── ReceiptCard.cs │ │ ├── ReceiptItem.cs │ │ ├── ResourceResponse.cs │ │ ├── SigninCard.cs │ │ ├── SuggestedActions.cs │ │ ├── Thing.cs │ │ ├── ThumbnailCard.cs │ │ ├── ThumbnailUrl.cs │ │ ├── TokenParameters.cs │ │ └── VideoCard.cs │ ├── RestExtensions.cs │ ├── Tokens.cs │ └── TokensExtensions.cs ├── DirectLineClient.cs ├── DirectLineClientCredentials.cs ├── EntityEx.cs ├── ErrorHandling.cs ├── Extensions.cs ├── IActivity.cs ├── IContactRelationUpdateActivity.cs ├── IConversationUpdate.cs ├── IEndOfConversationActivity.cs ├── IEventActivity.cs ├── IInstallationUpdateActivity.cs ├── IInvokeActivity.cs ├── IMessageActivity.cs ├── IMessageDeleteActivity.cs ├── IMessageUpdateActivity.cs ├── ITypingActivity.cs ├── InputHints.cs ├── InstallationUpdateActionTypes.cs ├── Microsoft.Bot.Connector.DirectLine.csproj ├── Microsoft.Bot.Connector.DirectLine.nuspec ├── Microsoft.Bot.Connector.DirectLine.sln ├── Properties │ └── AssemblyInfo.cs ├── Streaming │ ├── AttachmentStream.cs │ ├── DirectLineClient.cs │ ├── DirectLineRequestHandler.cs │ ├── IStreamingConversations.cs │ ├── OperationException.cs │ └── StreamingConversations.cs ├── app.config └── swagger.json └── samples ├── core-DirectLine ├── DirectLineBot.sln ├── DirectLineBot │ ├── AdapterWithErrorHandler.cs │ ├── Bots │ │ └── EchoBot.cs │ ├── Controllers │ │ └── BotController.cs │ ├── DirectLineBot.csproj │ ├── Program.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ └── default.htm ├── DirectLineClient │ ├── App.config │ ├── DirectLineSampleClient.csproj │ ├── Models │ │ └── DirectLineCardContent.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── README.md └── images │ ├── outcome-configure.png │ └── outcome.png └── core-DirectLineWebSockets ├── DirectLineBot.sln ├── DirectLineBot ├── AdapterWithErrorHandler.cs ├── Bots │ └── EchoBot.cs ├── Controllers │ └── BotController.cs ├── DirectLineBot.csproj ├── Program.cs ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ └── default.htm ├── DirectLineClient ├── App.config ├── DirectLineSampleClient.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── README.md └── images ├── outcome-configure.png └── outcome.png /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.doc diff=astextplain 4 | *.DOC diff=astextplain 5 | *.docx diff=astextplain 6 | *.DOCX diff=astextplain 7 | *.dot diff=astextplain 8 | *.DOT diff=astextplain 9 | *.pdf diff=astextplain 10 | *.PDF diff=astextplain 11 | *.rtf diff=astextplain 12 | *.RTF diff=astextplain 13 | 14 | *.jpg binary 15 | *.png binary 16 | *.gif binary 17 | 18 | *.cs text=auto diff=csharp 19 | *.vb text=auto 20 | *.resx text=auto 21 | *.c text=auto 22 | *.cpp text=auto 23 | *.cxx text=auto 24 | *.h text=auto 25 | *.hxx text=auto 26 | *.py text=auto 27 | *.rb text=auto 28 | *.java text=auto 29 | *.html text=auto 30 | *.htm text=auto 31 | *.css text=auto 32 | *.scss text=auto 33 | *.sass text=auto 34 | *.less text=auto 35 | *.js text=auto 36 | *.lisp text=auto 37 | *.clj text=auto 38 | *.sql text=auto 39 | *.php text=auto 40 | *.lua text=auto 41 | *.m text=auto 42 | *.asm text=auto 43 | *.erl text=auto 44 | *.fs text=auto 45 | *.fsx text=auto 46 | *.hs text=auto 47 | 48 | *.csproj text=auto 49 | *.vbproj text=auto 50 | *.fsproj text=auto 51 | *.dbproj text=auto 52 | *.sln text=auto eol=crlf 53 | 54 | *.sh eol=lf -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # More details are here: https://help.github.com/articles/about-codeowners/ 5 | 6 | # The '*' pattern is global owners. 7 | 8 | # Order is important. The last matching pattern has the most precedence. 9 | # The folders are ordered as follows: 10 | 11 | # In each subsection folders are ordered first by depth, then alphabetically. 12 | # This should make it easy to add new rules without breaking existing ones. 13 | 14 | # Global rule: 15 | * @microsoft/botframework-sdk -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/-net-directline-bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ".NET Directline Bug" 3 | about: Create a bug report for a bug you found in the Bot Framework .NET Directline SDK 4 | 5 | --- 6 | 7 | ### [Github issues](https://github.com/Microsoft/botframework-directline-dotnet/issues) should be used for bugs and feature requests. Use [Stack Overflow](https://stackoverflow.com/questions/tagged/botframework) for general "how-to" questions. 8 | 9 | ## Version 10 | What package version of the SDK are you using. 11 | 12 | ## Describe the bug 13 | Give a clear and concise description of what the bug is. 14 | 15 | ## To Reproduce 16 | Steps to reproduce the behavior: 17 | 1. Go to '...' 18 | 2. Click on '....' 19 | 3. Scroll down to '....' 20 | 4. See error 21 | 22 | ## Expected behavior 23 | Give a clear and concise description of what you expected to happen. 24 | 25 | ## Screenshots 26 | If applicable, add screenshots to help explain your problem. 27 | 28 | ## Additional context 29 | Add any other context about the problem here. 30 | 31 | [bug] 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/-net-directline-feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ".NET Directline Feature Request" 3 | about: Suggest a feature for the Bot Framework .NET Directline SDK 4 | 5 | --- 6 | 7 | ### Use this [query](https://github.com/Microsoft/botframework-directline-dotnet/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen++label%3Aenhancement) to search for the most popular feature requests. 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | 21 | [enhancement] 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/-net-directline-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ".NET Directline Question" 3 | about: The issue tracker is not for questions. Please ask questions on https://stackoverflow.com/questions/tagged/botframework 4 | 5 | --- 6 | 7 | 🚨 The issue tracker is not for questions 🚨 8 | 9 | If you have a question, please ask it on https://stackoverflow.com/questions/tagged/botframework 10 | 11 | [question] 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | ecf/ 24 | rcf/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # .NET Core 43 | *.lock.json 44 | artifacts/ 45 | **/Properties/launchSettings.json 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | 88 | # TFS 2012 Local Workspace 89 | $tf/ 90 | 91 | # Guidance Automation Toolkit 92 | *.gpState 93 | 94 | # ReSharper is a .NET coding add-in 95 | _ReSharper*/ 96 | *.[Rr]e[Ss]harper 97 | *.DotSettings.user 98 | 99 | # JustCode is a .NET coding add-in 100 | .JustCode 101 | 102 | # TeamCity is a build add-in 103 | _TeamCity* 104 | 105 | # DotCover is a Code Coverage Tool 106 | *.dotCover 107 | 108 | # NCrunch 109 | _NCrunch_* 110 | .*crunch*.local.xml 111 | 112 | # MightyMoose 113 | *.mm.* 114 | AutoTest.Net/ 115 | 116 | # Web workbench (sass) 117 | .sass-cache/ 118 | 119 | # Installshield output folder 120 | [Ee]xpress/ 121 | 122 | # DocProject is a documentation generator add-in 123 | DocProject/buildhelp/ 124 | DocProject/Help/*.HxT 125 | DocProject/Help/*.HxC 126 | DocProject/Help/*.hhc 127 | DocProject/Help/*.hhk 128 | DocProject/Help/*.hhp 129 | DocProject/Help/Html2 130 | DocProject/Help/html 131 | 132 | # Click-Once directory 133 | publish/ 134 | 135 | # Publish Web Output 136 | *.[Pp]ublish.xml 137 | ## TODO: Comment the next line if you want to checkin your 138 | ## web deploy settings but do note that will include unencrypted 139 | ## passwords 140 | ## TODO: note that next line is commented out, but at line ~283 (Azure publish profiles) the same file type is uncommented. 141 | #*.pubxml 142 | 143 | ## ignore imporeted publish xml files 144 | *intercom-botdirectory-scratch\ -\ FTP.pubxml 145 | *intercom-botdirectory-scratch\ -\ Web\ Deploy.pubxml 146 | 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | 158 | # Windows Azure Build Output 159 | csx/ 160 | *.build.csdef 161 | 162 | # Windows Store app package directory 163 | AppPackages/ 164 | 165 | # Visual Studio cache files 166 | # files ending in .cache can be ignored 167 | *.[Cc]ache 168 | # but keep track of directories ending in .cache 169 | !*.[Cc]ache/ 170 | 171 | # Others 172 | ClientBin/ 173 | [Ss]tyle[Cc]op.* 174 | ~$* 175 | *~ 176 | *.dbmdl 177 | *.dbproj.schemaview 178 | *.jfm 179 | *.pfx 180 | *.publishsettings 181 | orleans.codegen.cs 182 | 183 | # Since there are multiple workflows, uncomment next line to ignore bower_components 184 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 185 | #bower_components/ 186 | 187 | # RIA/Silverlight projects 188 | Generated_Code/ 189 | 190 | # Backup & report files from converting an old project file 191 | # to a newer Visual Studio version. Backup files are not needed, 192 | # because we have git ;-) 193 | _UpgradeReport_Files/ 194 | Backup*/ 195 | UpgradeLog*.XML 196 | UpgradeLog*.htm 197 | 198 | # SQL Server files 199 | *.mdf 200 | *.ldf 201 | *.ndf 202 | 203 | # Business Intelligence projects 204 | *.rdl.data 205 | *.bim.layout 206 | *.bim_*.settings 207 | 208 | # Microsoft Fakes 209 | FakesAssemblies/ 210 | 211 | # GhostDoc plugin setting file 212 | *.GhostDoc.xml 213 | 214 | # Node.js Tools for Visual Studio 215 | .ntvs_analysis.dat 216 | node_modules/ 217 | 218 | # Typescript v1 declaration files 219 | typings/ 220 | 221 | # Visual Studio 6 build log 222 | *.plg 223 | 224 | # Visual Studio 6 workspace options file 225 | *.opt 226 | 227 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 228 | *.vbw 229 | 230 | # Visual Studio LightSwitch build output 231 | **/*.HTMLClient/GeneratedArtifacts 232 | **/*.DesktopClient/GeneratedArtifacts 233 | **/*.DesktopClient/ModelManifest.xml 234 | **/*.Server/GeneratedArtifacts 235 | **/*.Server/ModelManifest.xml 236 | _Pvt_Extensions 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | paket-files/ 241 | 242 | # FAKE - F# Make 243 | .fake/ 244 | 245 | # JetBrains Rider 246 | .idea/ 247 | *.sln.iml 248 | 249 | # CodeRush 250 | .cr/ 251 | 252 | # Python Tools for Visual Studio (PTVS) 253 | __pycache__/ 254 | *.pyc 255 | 256 | # Cake - Uncomment if you are using it 257 | # tools/** 258 | # !tools/packages.config 259 | 260 | # Telerik's JustMock configuration file 261 | *.jmconfig 262 | 263 | # BizTalk build output 264 | *.btp.cs 265 | *.btm.cs 266 | *.odx.cs 267 | *.xsd.cs 268 | # LightSwitch generated files 269 | GeneratedArtifacts/ 270 | _Pvt_Extensions/ 271 | ModelManifest.xml 272 | /Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 273 | /Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml 274 | /PublishScripts/Scripts/Deploy-AzureResourceGroup-5.ps1 275 | /PublishScripts 276 | 277 | # User-specific files 278 | Documentation/Doxygen_warnings.txt 279 | 280 | # Build results 281 | Documentation/docs/ 282 | 283 | # Azure publish profiles 284 | *.pubxml 285 | PublishProfiles/ 286 | 287 | appsettings.local.json 288 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This project welcomes contributions and suggestions. Most contributions require you to 4 | agree to a Contributor License Agreement (CLA) declaring that you have the right to, 5 | and actually do, grant us the rights to use your contribution. For details, visit 6 | https://cla.microsoft.com. 7 | 8 | When you submit a pull request, a CLA-bot will automatically determine whether you need 9 | to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the 10 | instructions provided by the bot. You will only need to do this once across all repositories using our CLA. 11 | 12 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 13 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 14 | or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BotFramework-DirectLine-DotNet 2 | 3 | 4 | 5 | 6 | ## Contributing 7 | 8 | This project welcomes contributions and suggestions. Guidelines for contributions can be found in [CONTRIBUTING.md](./CONTRIBUTING.md) 9 | 10 | ## Reporting Security Issues 11 | Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [secure@microsoft.com](mailto:secure@microsoft.com). You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the [MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/default). 12 | 13 | ## License 14 | 15 | Copyright (c) Microsoft Corporation. All rights reserved. 16 | 17 | Licensed under the [MIT](/LICENSE.md) License. 18 | 19 | 20 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 21 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /build/35MSSharedLib1024.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/BotFramework-DirectLine-DotNet/7c4504777e057124e0ab0bd40e1a1891babbf35e/build/35MSSharedLib1024.snk -------------------------------------------------------------------------------- /build/ExtractCompressNuGet.ps1: -------------------------------------------------------------------------------- 1 | # 2 | # This extracts contents from or recompresses them back into NuGet .nupkg files. 3 | # Run this to extract before, then recompress after signing assemblies in the packages. 4 | # 5 | param 6 | ( 7 | [string]$path, 8 | [switch]$extract, 9 | [switch]$compress 10 | ) 11 | pushd $path 12 | 13 | # Download temporary version of Archive module that fixes issue on macOS/Linux with path separator 14 | #Invoke-WebRequest -Uri "https://raw.githubusercontent.com/PowerShell/Microsoft.PowerShell.Archive/master/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1" -OutFile .\archive.psm1 15 | #Import-Module .\archive.psm1 16 | 17 | # Ensure Powershell.Archive minimum version 1.2.3.0 is installed. That fixes a path separator issue on macOS/Linux. 18 | # An "ObjectNotFound" error can result from a temporary Powershell module repository outage. 19 | $ver = (Get-Command -Module Microsoft.PowerShell.Archive | Select-Object -Property version -First 1).Version.ToString() 20 | Write-Host "Currently installed: Microsoft.Powershell.Archive $ver" 21 | if ($ver -lt '1.2.3.0') { 22 | Write-Host "Installing Microsoft.Powershell.Archive 1.2.5 (fix for Linux path separator bug)" 23 | Install-Module -Name Microsoft.PowerShell.Archive -MinimumVersion '1.2.5' -AllowClobber -Force -AcceptLicense 24 | } 25 | 26 | [int]$itemsProcessed = 0 27 | if ($extract) { 28 | # Extract .nupkg packages in the path. 29 | Get-ChildItem . -Filter *.nupkg | 30 | Foreach-Object { 31 | Write-Host $_.Name 32 | Rename-Item -Path $_.Name -NewName ($_.BaseName + ".zip") 33 | Expand-Archive ($_.BaseName + '.zip') -DestinationPath ($_.BaseName) 34 | Remove-Item -Path ($_.DirectoryName + '\' + $_.BaseName + '.zip') 35 | $itemsProcessed++ 36 | } 37 | } elseif ($compress) { 38 | # Compress folders in the path. Name them *.nupkg. 39 | Get-ChildItem | ?{ $_.PSIsContainer } | 40 | Foreach-Object { 41 | Write-Host $_.Name 42 | Compress-Archive ($_.Name + '\**') -DestinationPath ($_.Name + '.zip') 43 | Rename-Item -Path ($_.Name + '.zip') -NewName ($_.BaseName + ".nupkg") 44 | Remove-Item -Path ($_.FullName) -Recurse 45 | $itemsProcessed++ 46 | } 47 | } else { 48 | throw 'Error: Missing argument "-Extract" or "-Compress".' 49 | } 50 | if ($itemsProcessed -eq 0) { 51 | Write-Host "No items found to process in path '$path'." 52 | } 53 | 54 | popd -------------------------------------------------------------------------------- /libraries/ActionTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Types of actions 11 | /// 12 | public class ActionTypes 13 | { 14 | /// 15 | /// Open the supplied URL in the built-in browser 16 | /// 17 | public const string OpenUrl = "openUrl"; 18 | 19 | /// 20 | /// Post message to bot. ImBack sends the action's Title. 21 | /// 22 | public const string ImBack = "imBack"; 23 | 24 | /// 25 | /// Post message to bot. PostBack displays the action's Title but sends the Title and Value. 26 | /// 27 | public const string PostBack = "postBack"; 28 | 29 | /// 30 | /// Open an audio playback container for the supplied URL 31 | /// 32 | public const string PlayAudio = "playAudio"; 33 | 34 | /// 35 | /// Open a video playback container for the supplied URL 36 | /// 37 | public const string PlayVideo = "playVideo"; 38 | 39 | /// 40 | /// Show image referenced by URL 41 | /// 42 | public const string ShowImage = "showImage"; 43 | 44 | /// 45 | /// Download file referenced by url 46 | /// 47 | public const string DownloadFile = "downloadFile"; 48 | 49 | /// 50 | /// Prompt the user to sign in 51 | /// 52 | public const string Signin = "signin"; 53 | 54 | /// 55 | /// Initiate a call 56 | /// 57 | public const string Call = "call"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /libraries/ActivityTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Types of Activities 11 | /// 12 | public class ActivityTypes 13 | { 14 | /// 15 | /// Message from a user -> bot or bot -> User 16 | /// 17 | public const string Message = "message"; 18 | 19 | /// 20 | /// Bot added removed to contact list 21 | /// 22 | public const string ContactRelationUpdate = "contactRelationUpdate"; 23 | 24 | /// 25 | /// This notification is sent when the conversation's properties change, for example the topic name, or when user joins or leaves the group. 26 | /// 27 | public const string ConversationUpdate = "conversationUpdate"; 28 | 29 | /// 30 | /// a user is typing 31 | /// 32 | public const string Typing = "typing"; 33 | 34 | /// 35 | /// Bounce a message off of the server without replying or changing it's state 36 | /// 37 | public const string Ping = "ping"; 38 | 39 | /// 40 | /// End a conversation 41 | /// 42 | public const string EndOfConversation = "endOfConversation"; 43 | 44 | /// 45 | /// Asynchronous external event 46 | /// 47 | public const string Event = "event"; 48 | 49 | /// 50 | /// Synchronous request to invoke a command 51 | /// 52 | public const string Invoke = "invoke"; 53 | 54 | /// 55 | /// Delete user data 56 | /// 57 | public const string DeleteUserData = "deleteUserData"; 58 | 59 | /// 60 | /// An update to an existing Message Activity 61 | /// 62 | public const string MessageUpdate = "messageUpdate"; 63 | 64 | /// 65 | /// Indicates a delete of an existing Message Activity 66 | /// 67 | public const string MessageDelete = "messageDelete"; 68 | 69 | /// 70 | /// Bot added or removed from channel 71 | /// 72 | public const string InstallationUpdate = "installationUpdate"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /libraries/Client/ConversationsExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using Microsoft.Rest; 16 | 17 | 18 | /// 19 | /// Extension methods for Conversations. 20 | /// 21 | public static partial class ConversationsExtensions 22 | { 23 | /// 24 | /// Start a new conversation 25 | /// 26 | /// 27 | /// The operations group for this extension method. 28 | /// 29 | public static Conversation StartConversation(this IConversations operations) 30 | { 31 | return Task.Factory.StartNew(s => ((IConversations)s).StartConversationAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 32 | } 33 | 34 | /// 35 | /// Start a new conversation 36 | /// 37 | /// 38 | /// The operations group for this extension method. 39 | /// 40 | /// 41 | /// The cancellation token. 42 | /// 43 | public static async Task StartConversationAsync(this IConversations operations, CancellationToken cancellationToken = default(CancellationToken)) 44 | { 45 | using (var _result = await operations.StartConversationWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)) 46 | { 47 | return _result.Body; 48 | } 49 | } 50 | 51 | /// 52 | /// Get information about an existing conversation 53 | /// 54 | /// 55 | /// The operations group for this extension method. 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | public static Conversation ReconnectToConversation(this IConversations operations, string conversationId, string watermark = default(string)) 62 | { 63 | return Task.Factory.StartNew(s => ((IConversations)s).ReconnectToConversationAsync(conversationId, watermark), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 64 | } 65 | 66 | /// 67 | /// Get information about an existing conversation 68 | /// 69 | /// 70 | /// The operations group for this extension method. 71 | /// 72 | /// 73 | /// 74 | /// 75 | /// 76 | /// 77 | /// The cancellation token. 78 | /// 79 | public static async Task ReconnectToConversationAsync(this IConversations operations, string conversationId, string watermark = default(string), CancellationToken cancellationToken = default(CancellationToken)) 80 | { 81 | using (var _result = await operations.ReconnectToConversationWithHttpMessagesAsync(conversationId, watermark, null, cancellationToken).ConfigureAwait(false)) 82 | { 83 | return _result.Body; 84 | } 85 | } 86 | 87 | /// 88 | /// Get activities in this conversation. This method is paged with the 89 | /// 'watermark' parameter. 90 | /// 91 | /// 92 | /// The operations group for this extension method. 93 | /// 94 | /// 95 | /// Conversation ID 96 | /// 97 | /// 98 | /// (Optional) only returns activities newer than this watermark 99 | /// 100 | public static ActivitySet GetActivities(this IConversations operations, string conversationId, string watermark = default(string)) 101 | { 102 | return Task.Factory.StartNew(s => ((IConversations)s).GetActivitiesAsync(conversationId, watermark), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 103 | } 104 | 105 | /// 106 | /// Get activities in this conversation. This method is paged with the 107 | /// 'watermark' parameter. 108 | /// 109 | /// 110 | /// The operations group for this extension method. 111 | /// 112 | /// 113 | /// Conversation ID 114 | /// 115 | /// 116 | /// (Optional) only returns activities newer than this watermark 117 | /// 118 | /// 119 | /// The cancellation token. 120 | /// 121 | public static async Task GetActivitiesAsync(this IConversations operations, string conversationId, string watermark = default(string), CancellationToken cancellationToken = default(CancellationToken)) 122 | { 123 | using (var _result = await operations.GetActivitiesWithHttpMessagesAsync(conversationId, watermark, null, cancellationToken).ConfigureAwait(false)) 124 | { 125 | return _result.Body; 126 | } 127 | } 128 | 129 | /// 130 | /// Send an activity 131 | /// 132 | /// 133 | /// The operations group for this extension method. 134 | /// 135 | /// 136 | /// Conversation ID 137 | /// 138 | /// 139 | /// Activity to send 140 | /// 141 | public static ResourceResponse PostActivity(this IConversations operations, string conversationId, Activity activity) 142 | { 143 | return Task.Factory.StartNew(s => ((IConversations)s).PostActivityAsync(conversationId, activity), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 144 | } 145 | 146 | /// 147 | /// Send an activity 148 | /// 149 | /// 150 | /// The operations group for this extension method. 151 | /// 152 | /// 153 | /// Conversation ID 154 | /// 155 | /// 156 | /// Activity to send 157 | /// 158 | /// 159 | /// The cancellation token. 160 | /// 161 | public static async Task PostActivityAsync(this IConversations operations, string conversationId, Activity activity, CancellationToken cancellationToken = default(CancellationToken)) 162 | { 163 | using (var _result = await operations.PostActivityWithHttpMessagesAsync(conversationId, activity, null, cancellationToken).ConfigureAwait(false)) 164 | { 165 | return _result.Body; 166 | } 167 | } 168 | 169 | /// 170 | /// Upload file(s) and send as attachment(s) 171 | /// 172 | /// 173 | /// The operations group for this extension method. 174 | /// 175 | /// 176 | /// 177 | /// 178 | /// 179 | /// 180 | /// 181 | public static ResourceResponse Upload(this IConversations operations, string conversationId, System.IO.Stream file, string userId = default(string), string contentType = null) 182 | { 183 | return Task.Factory.StartNew(s => ((IConversations)s).UploadAsync(conversationId, file, userId, contentType), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 184 | } 185 | 186 | /// 187 | /// Upload file(s) and send as attachment(s) 188 | /// 189 | /// 190 | /// The operations group for this extension method. 191 | /// 192 | /// 193 | /// 194 | /// 195 | /// 196 | /// 197 | /// 198 | /// 199 | /// The cancellation token. 200 | /// 201 | public static async Task UploadAsync(this IConversations operations, string conversationId, System.IO.Stream file, string userId = default(string), string contentType = null, CancellationToken cancellationToken = default(CancellationToken)) 202 | { 203 | using (var _result = await operations.UploadWithHttpMessagesAsync(conversationId, file, userId, contentType, null, cancellationToken).ConfigureAwait(false)) 204 | { 205 | return _result.Body; 206 | } 207 | } 208 | 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /libraries/Client/IConversations.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Net.Http; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using Microsoft.Rest; 16 | 17 | 18 | /// 19 | /// Conversations operations. 20 | /// 21 | public partial interface IConversations 22 | { 23 | /// 24 | /// Start a new conversation 25 | /// 26 | /// 27 | /// The headers that will be added to request. 28 | /// 29 | /// 30 | /// The cancellation token. 31 | /// 32 | Task> StartConversationWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 33 | /// 34 | /// Get information about an existing conversation 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// The headers that will be added to request. 42 | /// 43 | /// 44 | /// The cancellation token. 45 | /// 46 | Task> ReconnectToConversationWithHttpMessagesAsync(string conversationId, string watermark = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 47 | /// 48 | /// Get activities in this conversation. This method is paged with the 49 | /// 'watermark' parameter. 50 | /// 51 | /// 52 | /// Conversation ID 53 | /// 54 | /// 55 | /// (Optional) only returns activities newer than this watermark 56 | /// 57 | /// 58 | /// The headers that will be added to request. 59 | /// 60 | /// 61 | /// The cancellation token. 62 | /// 63 | Task> GetActivitiesWithHttpMessagesAsync(string conversationId, string watermark = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 64 | /// 65 | /// Send an activity 66 | /// 67 | /// 68 | /// Conversation ID 69 | /// 70 | /// 71 | /// Activity to send 72 | /// 73 | /// 74 | /// The headers that will be added to request. 75 | /// 76 | /// 77 | /// The cancellation token. 78 | /// 79 | Task> PostActivityWithHttpMessagesAsync(string conversationId, Activity activity, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 80 | /// 81 | /// Upload file(s) and send as attachment(s) 82 | /// 83 | /// 84 | /// 85 | /// 86 | /// 87 | /// 88 | /// 89 | /// 90 | /// The headers that will be added to request. 91 | /// 92 | /// 93 | /// The cancellation token. 94 | /// 95 | Task> UploadWithHttpMessagesAsync(string conversationId, System.IO.Stream file, string userId = default(string), string contentType = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /libraries/Client/ITokens.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Net.Http; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using Microsoft.Rest; 16 | 17 | 18 | /// 19 | /// Tokens operations. 20 | /// 21 | public partial interface ITokens 22 | { 23 | /// 24 | /// Refresh a token 25 | /// 26 | /// 27 | /// The headers that will be added to request. 28 | /// 29 | /// 30 | /// The cancellation token. 31 | /// 32 | Task> RefreshTokenWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 33 | /// 34 | /// Generate a token for a new conversation 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// The headers that will be added to request. 40 | /// 41 | /// 42 | /// The cancellation token. 43 | /// 44 | Task> GenerateTokenForNewConversationWithHttpMessagesAsync(TokenParameters tokenParameters = default(TokenParameters), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /libraries/Client/Models/ActivitySet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A collection of activities 19 | /// 20 | public partial class ActivitySet 21 | { 22 | /// 23 | /// Initializes a new instance of the ActivitySet class. 24 | /// 25 | public ActivitySet() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ActivitySet class. 29 | /// 30 | public ActivitySet(IList activities = default(IList), string watermark = default(string)) 31 | { 32 | Activities = activities; 33 | Watermark = watermark; 34 | } 35 | 36 | /// 37 | /// Activities 38 | /// 39 | [JsonProperty(PropertyName = "activities")] 40 | public IList Activities { get; set; } 41 | 42 | /// 43 | /// Maximum watermark of activities within this set 44 | /// 45 | [JsonProperty(PropertyName = "watermark")] 46 | public string Watermark { get; set; } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/Client/Models/AnimationCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An animation card (Ex: gif or short video clip) 19 | /// 20 | public partial class AnimationCard 21 | { 22 | /// 23 | /// Initializes a new instance of the AnimationCard class. 24 | /// 25 | public AnimationCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the AnimationCard class. 29 | /// 30 | public AnimationCard(string title = default(string), string subtitle = default(string), string text = default(string), ThumbnailUrl image = default(ThumbnailUrl), IList media = default(IList), IList buttons = default(IList), bool? shareable = default(bool?), bool? autoloop = default(bool?), bool? autostart = default(bool?)) 31 | { 32 | Title = title; 33 | Subtitle = subtitle; 34 | Text = text; 35 | Image = image; 36 | Media = media; 37 | Buttons = buttons; 38 | Shareable = shareable; 39 | Autoloop = autoloop; 40 | Autostart = autostart; 41 | } 42 | 43 | /// 44 | /// Title of the card 45 | /// 46 | [JsonProperty(PropertyName = "title")] 47 | public string Title { get; set; } 48 | 49 | /// 50 | /// Subtitle of the card 51 | /// 52 | [JsonProperty(PropertyName = "subtitle")] 53 | public string Subtitle { get; set; } 54 | 55 | /// 56 | /// Text of the card 57 | /// 58 | [JsonProperty(PropertyName = "text")] 59 | public string Text { get; set; } 60 | 61 | /// 62 | /// Thumbnail placeholder 63 | /// 64 | [JsonProperty(PropertyName = "image")] 65 | public ThumbnailUrl Image { get; set; } 66 | 67 | /// 68 | /// Array of media Url objects 69 | /// 70 | [JsonProperty(PropertyName = "media")] 71 | public IList Media { get; set; } 72 | 73 | /// 74 | /// Set of actions applicable to the current card 75 | /// 76 | [JsonProperty(PropertyName = "buttons")] 77 | public IList Buttons { get; set; } 78 | 79 | /// 80 | /// Is it OK for this content to be shareable with others 81 | /// (default:true) 82 | /// 83 | [JsonProperty(PropertyName = "shareable")] 84 | public bool? Shareable { get; set; } 85 | 86 | /// 87 | /// Should the client loop playback at end of content (default:true) 88 | /// 89 | [JsonProperty(PropertyName = "autoloop")] 90 | public bool? Autoloop { get; set; } 91 | 92 | /// 93 | /// Should the client automatically start playback of video in this 94 | /// card (default:true) 95 | /// 96 | [JsonProperty(PropertyName = "autostart")] 97 | public bool? Autostart { get; set; } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /libraries/Client/Models/Attachment.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An attachment within an activity 19 | /// 20 | public partial class Attachment 21 | { 22 | /// 23 | /// Initializes a new instance of the Attachment class. 24 | /// 25 | public Attachment() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Attachment class. 29 | /// 30 | public Attachment(string contentType = default(string), string contentUrl = default(string), object content = default(object), string name = default(string), string thumbnailUrl = default(string)) 31 | { 32 | ContentType = contentType; 33 | ContentUrl = contentUrl; 34 | Content = content; 35 | Name = name; 36 | ThumbnailUrl = thumbnailUrl; 37 | } 38 | 39 | /// 40 | /// mimetype/Contenttype for the file 41 | /// 42 | [JsonProperty(PropertyName = "contentType")] 43 | public string ContentType { get; set; } 44 | 45 | /// 46 | /// Content Url 47 | /// 48 | [JsonProperty(PropertyName = "contentUrl")] 49 | public string ContentUrl { get; set; } 50 | 51 | /// 52 | /// Embedded content 53 | /// 54 | [JsonProperty(PropertyName = "content")] 55 | public object Content { get; set; } 56 | 57 | /// 58 | /// (OPTIONAL) The name of the attachment 59 | /// 60 | [JsonProperty(PropertyName = "name")] 61 | public string Name { get; set; } 62 | 63 | /// 64 | /// (OPTIONAL) Thumbnail associated with attachment 65 | /// 66 | [JsonProperty(PropertyName = "thumbnailUrl")] 67 | public string ThumbnailUrl { get; set; } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /libraries/Client/Models/AudioCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A audio card 19 | /// 20 | public partial class AudioCard 21 | { 22 | /// 23 | /// Initializes a new instance of the AudioCard class. 24 | /// 25 | public AudioCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the AudioCard class. 29 | /// 30 | public AudioCard(string aspect = default(string), string title = default(string), string subtitle = default(string), string text = default(string), ThumbnailUrl image = default(ThumbnailUrl), IList media = default(IList), IList buttons = default(IList), bool? shareable = default(bool?), bool? autoloop = default(bool?), bool? autostart = default(bool?)) 31 | { 32 | Aspect = aspect; 33 | Title = title; 34 | Subtitle = subtitle; 35 | Text = text; 36 | Image = image; 37 | Media = media; 38 | Buttons = buttons; 39 | Shareable = shareable; 40 | Autoloop = autoloop; 41 | Autostart = autostart; 42 | } 43 | 44 | /// 45 | /// Aspect ratio of thumbnail/media placeholder, allowed values are 46 | /// "16x9" and "9x16" 47 | /// 48 | [JsonProperty(PropertyName = "aspect")] 49 | public string Aspect { get; set; } 50 | 51 | /// 52 | /// Title of the card 53 | /// 54 | [JsonProperty(PropertyName = "title")] 55 | public string Title { get; set; } 56 | 57 | /// 58 | /// Subtitle of the card 59 | /// 60 | [JsonProperty(PropertyName = "subtitle")] 61 | public string Subtitle { get; set; } 62 | 63 | /// 64 | /// Text of the card 65 | /// 66 | [JsonProperty(PropertyName = "text")] 67 | public string Text { get; set; } 68 | 69 | /// 70 | /// Thumbnail placeholder 71 | /// 72 | [JsonProperty(PropertyName = "image")] 73 | public ThumbnailUrl Image { get; set; } 74 | 75 | /// 76 | /// Array of media Url objects 77 | /// 78 | [JsonProperty(PropertyName = "media")] 79 | public IList Media { get; set; } 80 | 81 | /// 82 | /// Set of actions applicable to the current card 83 | /// 84 | [JsonProperty(PropertyName = "buttons")] 85 | public IList Buttons { get; set; } 86 | 87 | /// 88 | /// Is it OK for this content to be shareable with others 89 | /// (default:true) 90 | /// 91 | [JsonProperty(PropertyName = "shareable")] 92 | public bool? Shareable { get; set; } 93 | 94 | /// 95 | /// Should the client loop playback at end of content (default:true) 96 | /// 97 | [JsonProperty(PropertyName = "autoloop")] 98 | public bool? Autoloop { get; set; } 99 | 100 | /// 101 | /// Should the client automatically start playback of video in this 102 | /// card (default:true) 103 | /// 104 | [JsonProperty(PropertyName = "autostart")] 105 | public bool? Autostart { get; set; } 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /libraries/Client/Models/CardAction.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An action on a card 19 | /// 20 | public partial class CardAction 21 | { 22 | /// 23 | /// Initializes a new instance of the CardAction class. 24 | /// 25 | public CardAction() { } 26 | 27 | /// 28 | /// Initializes a new instance of the CardAction class. 29 | /// 30 | public CardAction(string type = default(string), string title = default(string), string image = default(string), object value = default(object)) 31 | { 32 | Type = type; 33 | Title = title; 34 | Image = image; 35 | Value = value; 36 | } 37 | 38 | /// 39 | /// Defines the type of action implemented by this button. 40 | /// 41 | [JsonProperty(PropertyName = "type")] 42 | public string Type { get; set; } 43 | 44 | /// 45 | /// Text description which appear on the button. 46 | /// 47 | [JsonProperty(PropertyName = "title")] 48 | public string Title { get; set; } 49 | 50 | /// 51 | /// URL Picture which will appear on the button, next to text label. 52 | /// 53 | [JsonProperty(PropertyName = "image")] 54 | public string Image { get; set; } 55 | 56 | /// 57 | /// Supplementary parameter for action. Content of this property 58 | /// depends on the ActionType 59 | /// 60 | [JsonProperty(PropertyName = "value")] 61 | public object Value { get; set; } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /libraries/Client/Models/CardImage.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An image on a card 19 | /// 20 | public partial class CardImage 21 | { 22 | /// 23 | /// Initializes a new instance of the CardImage class. 24 | /// 25 | public CardImage() { } 26 | 27 | /// 28 | /// Initializes a new instance of the CardImage class. 29 | /// 30 | public CardImage(string url = default(string), string alt = default(string), CardAction tap = default(CardAction)) 31 | { 32 | Url = url; 33 | Alt = alt; 34 | Tap = tap; 35 | } 36 | 37 | /// 38 | /// URL thumbnail image for major content property 39 | /// 40 | [JsonProperty(PropertyName = "url")] 41 | public string Url { get; set; } 42 | 43 | /// 44 | /// Image description intended for screen readers 45 | /// 46 | [JsonProperty(PropertyName = "alt")] 47 | public string Alt { get; set; } 48 | 49 | /// 50 | /// Action assigned to specific Attachment 51 | /// 52 | [JsonProperty(PropertyName = "tap")] 53 | public CardAction Tap { get; set; } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libraries/Client/Models/ChannelAccount.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Channel account information needed to route a message 19 | /// 20 | public partial class ChannelAccount 21 | { 22 | /// 23 | /// Initializes a new instance of the ChannelAccount class. 24 | /// 25 | public ChannelAccount() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ChannelAccount class. 29 | /// 30 | public ChannelAccount(string id = default(string), string name = default(string)) 31 | { 32 | Id = id; 33 | Name = name; 34 | } 35 | 36 | /// 37 | /// Channel id for the user or bot on this channel (Example: 38 | /// cid:abc123id or 123456) 39 | /// 40 | [JsonProperty(PropertyName = "id")] 41 | public string Id { get; set; } 42 | 43 | /// 44 | /// Display friendly name 45 | /// 46 | [JsonProperty(PropertyName = "name")] 47 | public string Name { get; set; } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /libraries/Client/Models/Conversation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An object representing a conversation or a conversation token 19 | /// 20 | public partial class Conversation 21 | { 22 | /// 23 | /// Initializes a new instance of the Conversation class. 24 | /// 25 | public Conversation() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Conversation class. 29 | /// 30 | public Conversation(string conversationId = default(string), string token = default(string), int? expiresIn = default(int?), string streamUrl = default(string), string referenceGrammarId = default(string), string eTag = default(string)) 31 | { 32 | ConversationId = conversationId; 33 | Token = token; 34 | ExpiresIn = expiresIn; 35 | StreamUrl = streamUrl; 36 | ReferenceGrammarId = referenceGrammarId; 37 | ETag = eTag; 38 | } 39 | 40 | /// 41 | /// ID for this conversation 42 | /// 43 | [JsonProperty(PropertyName = "conversationId")] 44 | public string ConversationId { get; set; } 45 | 46 | /// 47 | /// Token scoped to this conversation 48 | /// 49 | [JsonProperty(PropertyName = "token")] 50 | public string Token { get; set; } 51 | 52 | /// 53 | /// Expiration for token 54 | /// 55 | [JsonProperty(PropertyName = "expires_in")] 56 | public int? ExpiresIn { get; set; } 57 | 58 | /// 59 | /// URL for this conversation's message stream 60 | /// 61 | [JsonProperty(PropertyName = "streamUrl")] 62 | public string StreamUrl { get; set; } 63 | 64 | /// 65 | /// ID for the reference grammar for this bot 66 | /// 67 | [JsonProperty(PropertyName = "referenceGrammarId")] 68 | public string ReferenceGrammarId { get; set; } 69 | 70 | /// 71 | /// 72 | [JsonProperty(PropertyName = "eTag")] 73 | public string ETag { get; set; } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /libraries/Client/Models/ConversationAccount.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Channel account information for a conversation 19 | /// 20 | public partial class ConversationAccount 21 | { 22 | /// 23 | /// Initializes a new instance of the ConversationAccount class. 24 | /// 25 | public ConversationAccount() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ConversationAccount class. 29 | /// 30 | public ConversationAccount(bool? isGroup = default(bool?), string id = default(string), string name = default(string)) 31 | { 32 | IsGroup = isGroup; 33 | Id = id; 34 | Name = name; 35 | } 36 | 37 | /// 38 | /// Is this a reference to a group 39 | /// 40 | [JsonProperty(PropertyName = "isGroup")] 41 | public bool? IsGroup { get; set; } 42 | 43 | /// 44 | /// Channel id for the user or bot on this channel (Example: 45 | /// cid:abc123id or 123456) 46 | /// 47 | [JsonProperty(PropertyName = "id")] 48 | public string Id { get; set; } 49 | 50 | /// 51 | /// Display friendly name 52 | /// 53 | [JsonProperty(PropertyName = "name")] 54 | public string Name { get; set; } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /libraries/Client/Models/ConversationReference.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An object relating to a particular point in a conversation 19 | /// 20 | public partial class ConversationReference 21 | { 22 | /// 23 | /// Initializes a new instance of the ConversationReference class. 24 | /// 25 | public ConversationReference() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ConversationReference class. 29 | /// 30 | public ConversationReference(string activityId = default(string), ChannelAccount user = default(ChannelAccount), ChannelAccount bot = default(ChannelAccount), ConversationAccount conversation = default(ConversationAccount), string channelId = default(string), string serviceUrl = default(string)) 31 | { 32 | ActivityId = activityId; 33 | User = user; 34 | Bot = bot; 35 | Conversation = conversation; 36 | ChannelId = channelId; 37 | ServiceUrl = serviceUrl; 38 | } 39 | 40 | /// 41 | /// (Optional) ID of the activity to refer to 42 | /// 43 | [JsonProperty(PropertyName = "activityId")] 44 | public string ActivityId { get; set; } 45 | 46 | /// 47 | /// (Optional) User participating in this conversation 48 | /// 49 | [JsonProperty(PropertyName = "user")] 50 | public ChannelAccount User { get; set; } 51 | 52 | /// 53 | /// Bot participating in this conversation 54 | /// 55 | [JsonProperty(PropertyName = "bot")] 56 | public ChannelAccount Bot { get; set; } 57 | 58 | /// 59 | /// Conversation reference 60 | /// 61 | [JsonProperty(PropertyName = "conversation")] 62 | public ConversationAccount Conversation { get; set; } 63 | 64 | /// 65 | /// Channel ID 66 | /// 67 | [JsonProperty(PropertyName = "channelId")] 68 | public string ChannelId { get; set; } 69 | 70 | /// 71 | /// Service endpoint where operations concerning the referenced 72 | /// conversation may be performed 73 | /// 74 | [JsonProperty(PropertyName = "serviceUrl")] 75 | public string ServiceUrl { get; set; } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /libraries/Client/Models/Entity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Object of schema.org types 19 | /// 20 | public partial class Entity 21 | { 22 | /// 23 | /// Initializes a new instance of the Entity class. 24 | /// 25 | public Entity() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Entity class. 29 | /// 30 | public Entity(string type = default(string)) 31 | { 32 | Type = type; 33 | } 34 | 35 | /// 36 | /// Entity Type (typically from schema.org types) 37 | /// 38 | [JsonProperty(PropertyName = "type")] 39 | public string Type { get; set; } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /libraries/Client/Models/Error.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Object representing error information 19 | /// 20 | public partial class Error 21 | { 22 | /// 23 | /// Initializes a new instance of the Error class. 24 | /// 25 | public Error() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Error class. 29 | /// 30 | public Error(string code = default(string), string message = default(string)) 31 | { 32 | Code = code; 33 | Message = message; 34 | } 35 | 36 | /// 37 | /// Error code 38 | /// 39 | [JsonProperty(PropertyName = "code")] 40 | public string Code { get; set; } 41 | 42 | /// 43 | /// Error message 44 | /// 45 | [JsonProperty(PropertyName = "message")] 46 | public string Message { get; set; } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/Client/Models/ErrorResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An HTTP API response 19 | /// 20 | public partial class ErrorResponse 21 | { 22 | /// 23 | /// Initializes a new instance of the ErrorResponse class. 24 | /// 25 | public ErrorResponse() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ErrorResponse class. 29 | /// 30 | public ErrorResponse(Error error = default(Error)) 31 | { 32 | Error = error; 33 | } 34 | 35 | /// 36 | /// Error message 37 | /// 38 | [JsonProperty(PropertyName = "error")] 39 | public Error Error { get; set; } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /libraries/Client/Models/Fact.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Set of key-value pairs. Advantage of this section is that key and 19 | /// value properties will be 20 | /// rendered with default style information with some 21 | /// delimiter between them. So there is no need for developer to specify 22 | /// style information. 23 | /// 24 | public partial class Fact 25 | { 26 | /// 27 | /// Initializes a new instance of the Fact class. 28 | /// 29 | public Fact() { } 30 | 31 | /// 32 | /// Initializes a new instance of the Fact class. 33 | /// 34 | public Fact(string key = default(string), string value = default(string)) 35 | { 36 | Key = key; 37 | Value = value; 38 | } 39 | 40 | /// 41 | /// The key for this Fact 42 | /// 43 | [JsonProperty(PropertyName = "key")] 44 | public string Key { get; set; } 45 | 46 | /// 47 | /// The value for this Fact 48 | /// 49 | [JsonProperty(PropertyName = "value")] 50 | public string Value { get; set; } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /libraries/Client/Models/GeoCoordinates.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// GeoCoordinates (entity type: "https://schema.org/GeoCoordinates") 19 | /// 20 | public partial class GeoCoordinates 21 | { 22 | /// 23 | /// Initializes a new instance of the GeoCoordinates class. 24 | /// 25 | public GeoCoordinates() { } 26 | 27 | /// 28 | /// Initializes a new instance of the GeoCoordinates class. 29 | /// 30 | public GeoCoordinates(double? elevation = default(double?), double? latitude = default(double?), double? longitude = default(double?), string type = default(string), string name = default(string)) 31 | { 32 | Elevation = elevation; 33 | Latitude = latitude; 34 | Longitude = longitude; 35 | Type = type; 36 | Name = name; 37 | } 38 | 39 | /// 40 | /// Elevation of the location [WGS 41 | /// 84](https://en.wikipedia.org/wiki/World_Geodetic_System) 42 | /// 43 | [JsonProperty(PropertyName = "elevation")] 44 | public double? Elevation { get; set; } 45 | 46 | /// 47 | /// Latitude of the location [WGS 48 | /// 84](https://en.wikipedia.org/wiki/World_Geodetic_System) 49 | /// 50 | [JsonProperty(PropertyName = "latitude")] 51 | public double? Latitude { get; set; } 52 | 53 | /// 54 | /// Longitude of the location [WGS 55 | /// 84](https://en.wikipedia.org/wiki/World_Geodetic_System) 56 | /// 57 | [JsonProperty(PropertyName = "longitude")] 58 | public double? Longitude { get; set; } 59 | 60 | /// 61 | /// The type of the thing 62 | /// 63 | [JsonProperty(PropertyName = "type")] 64 | public string Type { get; set; } 65 | 66 | /// 67 | /// The name of the thing 68 | /// 69 | [JsonProperty(PropertyName = "name")] 70 | public string Name { get; set; } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /libraries/Client/Models/HeroCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A Hero card (card with a single, large image) 19 | /// 20 | public partial class HeroCard 21 | { 22 | /// 23 | /// Initializes a new instance of the HeroCard class. 24 | /// 25 | public HeroCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the HeroCard class. 29 | /// 30 | public HeroCard(string title = default(string), string subtitle = default(string), string text = default(string), IList images = default(IList), IList buttons = default(IList), CardAction tap = default(CardAction)) 31 | { 32 | Title = title; 33 | Subtitle = subtitle; 34 | Text = text; 35 | Images = images; 36 | Buttons = buttons; 37 | Tap = tap; 38 | } 39 | 40 | /// 41 | /// Title of the card 42 | /// 43 | [JsonProperty(PropertyName = "title")] 44 | public string Title { get; set; } 45 | 46 | /// 47 | /// Subtitle of the card 48 | /// 49 | [JsonProperty(PropertyName = "subtitle")] 50 | public string Subtitle { get; set; } 51 | 52 | /// 53 | /// Text for the card 54 | /// 55 | [JsonProperty(PropertyName = "text")] 56 | public string Text { get; set; } 57 | 58 | /// 59 | /// Array of images for the card 60 | /// 61 | [JsonProperty(PropertyName = "images")] 62 | public IList Images { get; set; } 63 | 64 | /// 65 | /// Set of actions applicable to the current card 66 | /// 67 | [JsonProperty(PropertyName = "buttons")] 68 | public IList Buttons { get; set; } 69 | 70 | /// 71 | /// This action will be activated when user taps on the card itself 72 | /// 73 | [JsonProperty(PropertyName = "tap")] 74 | public CardAction Tap { get; set; } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /libraries/Client/Models/MediaUrl.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// MediaUrl data 19 | /// 20 | public partial class MediaUrl 21 | { 22 | /// 23 | /// Initializes a new instance of the MediaUrl class. 24 | /// 25 | public MediaUrl() { } 26 | 27 | /// 28 | /// Initializes a new instance of the MediaUrl class. 29 | /// 30 | public MediaUrl(string url = default(string), string profile = default(string)) 31 | { 32 | Url = url; 33 | Profile = profile; 34 | } 35 | 36 | /// 37 | /// Url for the media 38 | /// 39 | [JsonProperty(PropertyName = "url")] 40 | public string Url { get; set; } 41 | 42 | /// 43 | /// Optional profile hint to the client to differentiate multiple 44 | /// MediaUrl objects from each other 45 | /// 46 | [JsonProperty(PropertyName = "profile")] 47 | public string Profile { get; set; } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /libraries/Client/Models/Mention.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Mention information (entity type: "mention") 19 | /// 20 | public partial class Mention 21 | { 22 | /// 23 | /// Initializes a new instance of the Mention class. 24 | /// 25 | public Mention() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Mention class. 29 | /// 30 | public Mention(ChannelAccount mentioned = default(ChannelAccount), string text = default(string), string type = default(string)) 31 | { 32 | Mentioned = mentioned; 33 | Text = text; 34 | Type = type; 35 | } 36 | 37 | /// 38 | /// The mentioned user 39 | /// 40 | [JsonProperty(PropertyName = "mentioned")] 41 | public ChannelAccount Mentioned { get; set; } 42 | 43 | /// 44 | /// Sub Text which represents the mention (can be null or empty) 45 | /// 46 | [JsonProperty(PropertyName = "text")] 47 | public string Text { get; set; } 48 | 49 | /// 50 | /// Entity Type (typically from schema.org types) 51 | /// 52 | [JsonProperty(PropertyName = "type")] 53 | public string Type { get; set; } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libraries/Client/Models/Place.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Place (entity type: "https://schema.org/Place") 19 | /// 20 | public partial class Place 21 | { 22 | /// 23 | /// Initializes a new instance of the Place class. 24 | /// 25 | public Place() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Place class. 29 | /// 30 | public Place(object address = default(object), object geo = default(object), object hasMap = default(object), string type = default(string), string name = default(string)) 31 | { 32 | Address = address; 33 | Geo = geo; 34 | HasMap = hasMap; 35 | Type = type; 36 | Name = name; 37 | } 38 | 39 | /// 40 | /// Address of the place (may be `string` or complex object of type 41 | /// `PostalAddress`) 42 | /// 43 | [JsonProperty(PropertyName = "address")] 44 | public object Address { get; set; } 45 | 46 | /// 47 | /// Geo coordinates of the place (may be complex object of type 48 | /// `GeoCoordinates` or `GeoShape`) 49 | /// 50 | [JsonProperty(PropertyName = "geo")] 51 | public object Geo { get; set; } 52 | 53 | /// 54 | /// Map to the place (may be `string` (URL) or complex object of type 55 | /// `Map`) 56 | /// 57 | [JsonProperty(PropertyName = "hasMap")] 58 | public object HasMap { get; set; } 59 | 60 | /// 61 | /// The type of the thing 62 | /// 63 | [JsonProperty(PropertyName = "type")] 64 | public string Type { get; set; } 65 | 66 | /// 67 | /// The name of the thing 68 | /// 69 | [JsonProperty(PropertyName = "name")] 70 | public string Name { get; set; } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /libraries/Client/Models/ReceiptCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A receipt card 19 | /// 20 | public partial class ReceiptCard 21 | { 22 | /// 23 | /// Initializes a new instance of the ReceiptCard class. 24 | /// 25 | public ReceiptCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ReceiptCard class. 29 | /// 30 | public ReceiptCard(string title = default(string), IList items = default(IList), IList facts = default(IList), CardAction tap = default(CardAction), string total = default(string), string tax = default(string), string vat = default(string), IList buttons = default(IList)) 31 | { 32 | Title = title; 33 | Items = items; 34 | Facts = facts; 35 | Tap = tap; 36 | Total = total; 37 | Tax = tax; 38 | Vat = vat; 39 | Buttons = buttons; 40 | } 41 | 42 | /// 43 | /// Title of the card 44 | /// 45 | [JsonProperty(PropertyName = "title")] 46 | public string Title { get; set; } 47 | 48 | /// 49 | /// Array of Receipt Items 50 | /// 51 | [JsonProperty(PropertyName = "items")] 52 | public IList Items { get; set; } 53 | 54 | /// 55 | /// Array of Fact Objects Array of key-value pairs. 56 | /// 57 | [JsonProperty(PropertyName = "facts")] 58 | public IList Facts { get; set; } 59 | 60 | /// 61 | /// This action will be activated when user taps on the card 62 | /// 63 | [JsonProperty(PropertyName = "tap")] 64 | public CardAction Tap { get; set; } 65 | 66 | /// 67 | /// Total amount of money paid (or should be paid) 68 | /// 69 | [JsonProperty(PropertyName = "total")] 70 | public string Total { get; set; } 71 | 72 | /// 73 | /// Total amount of TAX paid(or should be paid) 74 | /// 75 | [JsonProperty(PropertyName = "tax")] 76 | public string Tax { get; set; } 77 | 78 | /// 79 | /// Total amount of VAT paid(or should be paid) 80 | /// 81 | [JsonProperty(PropertyName = "vat")] 82 | public string Vat { get; set; } 83 | 84 | /// 85 | /// Set of actions applicable to the current card 86 | /// 87 | [JsonProperty(PropertyName = "buttons")] 88 | public IList Buttons { get; set; } 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /libraries/Client/Models/ReceiptItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// An item on a receipt card 19 | /// 20 | public partial class ReceiptItem 21 | { 22 | /// 23 | /// Initializes a new instance of the ReceiptItem class. 24 | /// 25 | public ReceiptItem() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ReceiptItem class. 29 | /// 30 | public ReceiptItem(string title = default(string), string subtitle = default(string), string text = default(string), CardImage image = default(CardImage), string price = default(string), string quantity = default(string), CardAction tap = default(CardAction)) 31 | { 32 | Title = title; 33 | Subtitle = subtitle; 34 | Text = text; 35 | Image = image; 36 | Price = price; 37 | Quantity = quantity; 38 | Tap = tap; 39 | } 40 | 41 | /// 42 | /// Title of the Card 43 | /// 44 | [JsonProperty(PropertyName = "title")] 45 | public string Title { get; set; } 46 | 47 | /// 48 | /// Subtitle appears just below Title field, differs from Title in 49 | /// font styling only 50 | /// 51 | [JsonProperty(PropertyName = "subtitle")] 52 | public string Subtitle { get; set; } 53 | 54 | /// 55 | /// Text field appears just below subtitle, differs from Subtitle in 56 | /// font styling only 57 | /// 58 | [JsonProperty(PropertyName = "text")] 59 | public string Text { get; set; } 60 | 61 | /// 62 | /// Image 63 | /// 64 | [JsonProperty(PropertyName = "image")] 65 | public CardImage Image { get; set; } 66 | 67 | /// 68 | /// Amount with currency 69 | /// 70 | [JsonProperty(PropertyName = "price")] 71 | public string Price { get; set; } 72 | 73 | /// 74 | /// Number of items of given kind 75 | /// 76 | [JsonProperty(PropertyName = "quantity")] 77 | public string Quantity { get; set; } 78 | 79 | /// 80 | /// This action will be activated when user taps on the Item bubble. 81 | /// 82 | [JsonProperty(PropertyName = "tap")] 83 | public CardAction Tap { get; set; } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /libraries/Client/Models/ResourceResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A response containing a resource ID 19 | /// 20 | public partial class ResourceResponse 21 | { 22 | /// 23 | /// Initializes a new instance of the ResourceResponse class. 24 | /// 25 | public ResourceResponse() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ResourceResponse class. 29 | /// 30 | public ResourceResponse(string id = default(string)) 31 | { 32 | Id = id; 33 | } 34 | 35 | /// 36 | /// Id of the resource 37 | /// 38 | [JsonProperty(PropertyName = "id")] 39 | public string Id { get; set; } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /libraries/Client/Models/SigninCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A card representing a request to sign in 19 | /// 20 | public partial class SigninCard 21 | { 22 | /// 23 | /// Initializes a new instance of the SigninCard class. 24 | /// 25 | public SigninCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the SigninCard class. 29 | /// 30 | public SigninCard(string text = default(string), IList buttons = default(IList)) 31 | { 32 | Text = text; 33 | Buttons = buttons; 34 | } 35 | 36 | /// 37 | /// Text for signin request 38 | /// 39 | [JsonProperty(PropertyName = "text")] 40 | public string Text { get; set; } 41 | 42 | /// 43 | /// Action to use to perform signin 44 | /// 45 | [JsonProperty(PropertyName = "buttons")] 46 | public IList Buttons { get; set; } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/Client/Models/SuggestedActions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// SuggestedActions that can be performed 19 | /// 20 | public partial class SuggestedActions 21 | { 22 | /// 23 | /// Initializes a new instance of the SuggestedActions class. 24 | /// 25 | public SuggestedActions() { } 26 | 27 | /// 28 | /// Initializes a new instance of the SuggestedActions class. 29 | /// 30 | public SuggestedActions(IList to = default(IList), IList actions = default(IList)) 31 | { 32 | To = to; 33 | Actions = actions; 34 | } 35 | 36 | /// 37 | /// Ids of the recipients that the actions should be shown to. These 38 | /// Ids are relative to the channelId and a subset of all recipients 39 | /// of the activity 40 | /// 41 | [JsonProperty(PropertyName = "to")] 42 | public IList To { get; set; } 43 | 44 | /// 45 | /// Actions that can be shown to the user 46 | /// 47 | [JsonProperty(PropertyName = "actions")] 48 | public IList Actions { get; set; } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /libraries/Client/Models/Thing.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Thing (entity type: "https://schema.org/Thing") 19 | /// 20 | public partial class Thing 21 | { 22 | /// 23 | /// Initializes a new instance of the Thing class. 24 | /// 25 | public Thing() { } 26 | 27 | /// 28 | /// Initializes a new instance of the Thing class. 29 | /// 30 | public Thing(string type = default(string), string name = default(string)) 31 | { 32 | Type = type; 33 | Name = name; 34 | } 35 | 36 | /// 37 | /// The type of the thing 38 | /// 39 | [JsonProperty(PropertyName = "type")] 40 | public string Type { get; set; } 41 | 42 | /// 43 | /// The name of the thing 44 | /// 45 | [JsonProperty(PropertyName = "name")] 46 | public string Name { get; set; } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/Client/Models/ThumbnailCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A thumbnail card (card with a single, small thumbnail image) 19 | /// 20 | public partial class ThumbnailCard 21 | { 22 | /// 23 | /// Initializes a new instance of the ThumbnailCard class. 24 | /// 25 | public ThumbnailCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ThumbnailCard class. 29 | /// 30 | public ThumbnailCard(string title = default(string), string subtitle = default(string), string text = default(string), IList images = default(IList), IList buttons = default(IList), CardAction tap = default(CardAction)) 31 | { 32 | Title = title; 33 | Subtitle = subtitle; 34 | Text = text; 35 | Images = images; 36 | Buttons = buttons; 37 | Tap = tap; 38 | } 39 | 40 | /// 41 | /// Title of the card 42 | /// 43 | [JsonProperty(PropertyName = "title")] 44 | public string Title { get; set; } 45 | 46 | /// 47 | /// Subtitle of the card 48 | /// 49 | [JsonProperty(PropertyName = "subtitle")] 50 | public string Subtitle { get; set; } 51 | 52 | /// 53 | /// Text for the card 54 | /// 55 | [JsonProperty(PropertyName = "text")] 56 | public string Text { get; set; } 57 | 58 | /// 59 | /// Array of images for the card 60 | /// 61 | [JsonProperty(PropertyName = "images")] 62 | public IList Images { get; set; } 63 | 64 | /// 65 | /// Set of actions applicable to the current card 66 | /// 67 | [JsonProperty(PropertyName = "buttons")] 68 | public IList Buttons { get; set; } 69 | 70 | /// 71 | /// This action will be activated when user taps on the card itself 72 | /// 73 | [JsonProperty(PropertyName = "tap")] 74 | public CardAction Tap { get; set; } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /libraries/Client/Models/ThumbnailUrl.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Object describing a media thumbnail 19 | /// 20 | public partial class ThumbnailUrl 21 | { 22 | /// 23 | /// Initializes a new instance of the ThumbnailUrl class. 24 | /// 25 | public ThumbnailUrl() { } 26 | 27 | /// 28 | /// Initializes a new instance of the ThumbnailUrl class. 29 | /// 30 | public ThumbnailUrl(string url = default(string), string alt = default(string)) 31 | { 32 | Url = url; 33 | Alt = alt; 34 | } 35 | 36 | /// 37 | /// url pointing to an thumbnail to use for media content 38 | /// 39 | [JsonProperty(PropertyName = "url")] 40 | public string Url { get; set; } 41 | 42 | /// 43 | /// Alt text to display for screen readers on the thumbnail image 44 | /// 45 | [JsonProperty(PropertyName = "alt")] 46 | public string Alt { get; set; } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/Client/Models/TokenParameters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// Parameters for creating a token 19 | /// 20 | public partial class TokenParameters 21 | { 22 | /// 23 | /// Initializes a new instance of the TokenParameters class. 24 | /// 25 | public TokenParameters() { } 26 | 27 | /// 28 | /// Initializes a new instance of the TokenParameters class. 29 | /// 30 | public TokenParameters(ChannelAccount user = default(ChannelAccount), string eTag = default(string)) 31 | { 32 | User = user; 33 | ETag = eTag; 34 | } 35 | 36 | /// 37 | /// User account to embed within the token 38 | /// 39 | [JsonProperty(PropertyName = "user")] 40 | public ChannelAccount User { get; set; } 41 | 42 | /// 43 | /// 44 | [JsonProperty(PropertyName = "eTag")] 45 | public string ETag { get; set; } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /libraries/Client/Models/VideoCard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Linq; 12 | using System.Collections.Generic; 13 | using Newtonsoft.Json; 14 | using Microsoft.Rest; 15 | using Microsoft.Rest.Serialization; 16 | 17 | /// 18 | /// A video card 19 | /// 20 | public partial class VideoCard 21 | { 22 | /// 23 | /// Initializes a new instance of the VideoCard class. 24 | /// 25 | public VideoCard() { } 26 | 27 | /// 28 | /// Initializes a new instance of the VideoCard class. 29 | /// 30 | public VideoCard(string aspect = default(string), string title = default(string), string subtitle = default(string), string text = default(string), ThumbnailUrl image = default(ThumbnailUrl), IList media = default(IList), IList buttons = default(IList), bool? shareable = default(bool?), bool? autoloop = default(bool?), bool? autostart = default(bool?)) 31 | { 32 | Aspect = aspect; 33 | Title = title; 34 | Subtitle = subtitle; 35 | Text = text; 36 | Image = image; 37 | Media = media; 38 | Buttons = buttons; 39 | Shareable = shareable; 40 | Autoloop = autoloop; 41 | Autostart = autostart; 42 | } 43 | 44 | /// 45 | /// Aspect ratio (16:9)(4:3) 46 | /// 47 | [JsonProperty(PropertyName = "aspect")] 48 | public string Aspect { get; set; } 49 | 50 | /// 51 | /// Title of the card 52 | /// 53 | [JsonProperty(PropertyName = "title")] 54 | public string Title { get; set; } 55 | 56 | /// 57 | /// Subtitle of the card 58 | /// 59 | [JsonProperty(PropertyName = "subtitle")] 60 | public string Subtitle { get; set; } 61 | 62 | /// 63 | /// Text of the card 64 | /// 65 | [JsonProperty(PropertyName = "text")] 66 | public string Text { get; set; } 67 | 68 | /// 69 | /// Thumbnail placeholder 70 | /// 71 | [JsonProperty(PropertyName = "image")] 72 | public ThumbnailUrl Image { get; set; } 73 | 74 | /// 75 | /// Array of media Url objects 76 | /// 77 | [JsonProperty(PropertyName = "media")] 78 | public IList Media { get; set; } 79 | 80 | /// 81 | /// Set of actions applicable to the current card 82 | /// 83 | [JsonProperty(PropertyName = "buttons")] 84 | public IList Buttons { get; set; } 85 | 86 | /// 87 | /// Is it OK for this content to be shareable with others 88 | /// (default:true) 89 | /// 90 | [JsonProperty(PropertyName = "shareable")] 91 | public bool? Shareable { get; set; } 92 | 93 | /// 94 | /// Should the client loop playback at end of content (default:true) 95 | /// 96 | [JsonProperty(PropertyName = "autoloop")] 97 | public bool? Autoloop { get; set; } 98 | 99 | /// 100 | /// Should the client automatically start playback of video in this 101 | /// card (default:true) 102 | /// 103 | [JsonProperty(PropertyName = "autostart")] 104 | public bool? Autostart { get; set; } 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /libraries/Client/RestExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Net.Http; 7 | using Microsoft.Rest; 8 | 9 | namespace Microsoft.Bot.Connector.DirectLine 10 | { 11 | public static class RestExtensions 12 | { 13 | public static HttpResponseMessageWrapper ForException(this HttpResponseMessage response, string content = "") 14 | { 15 | return new HttpResponseMessageWrapper(response, content); 16 | } 17 | 18 | public static HttpRequestMessageWrapper ForException(this HttpRequestMessage request, string content = "") 19 | { 20 | return new HttpRequestMessageWrapper(request, content); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libraries/Client/TokensExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using Microsoft.Rest; 16 | 17 | 18 | /// 19 | /// Extension methods for Tokens. 20 | /// 21 | public static partial class TokensExtensions 22 | { 23 | /// 24 | /// Refresh a token 25 | /// 26 | /// 27 | /// The operations group for this extension method. 28 | /// 29 | public static Conversation RefreshToken(this ITokens operations) 30 | { 31 | return Task.Factory.StartNew(s => ((ITokens)s).RefreshTokenAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 32 | } 33 | 34 | /// 35 | /// Refresh a token 36 | /// 37 | /// 38 | /// The operations group for this extension method. 39 | /// 40 | /// 41 | /// The cancellation token. 42 | /// 43 | public static async Task RefreshTokenAsync(this ITokens operations, CancellationToken cancellationToken = default(CancellationToken)) 44 | { 45 | using (var _result = await operations.RefreshTokenWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)) 46 | { 47 | return _result.Body; 48 | } 49 | } 50 | 51 | /// 52 | /// Generate a token for a new conversation 53 | /// 54 | /// 55 | /// The operations group for this extension method. 56 | /// 57 | /// 58 | /// 59 | public static Conversation GenerateTokenForNewConversation(this ITokens operations, TokenParameters tokenParameters = default(TokenParameters)) 60 | { 61 | return Task.Factory.StartNew(s => ((ITokens)s).GenerateTokenForNewConversationAsync(tokenParameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 62 | } 63 | 64 | /// 65 | /// Generate a token for a new conversation 66 | /// 67 | /// 68 | /// The operations group for this extension method. 69 | /// 70 | /// 71 | /// 72 | /// 73 | /// The cancellation token. 74 | /// 75 | public static async Task GenerateTokenForNewConversationAsync(this ITokens operations, TokenParameters tokenParameters = default(TokenParameters), CancellationToken cancellationToken = default(CancellationToken)) 76 | { 77 | using (var _result = await operations.GenerateTokenForNewConversationWithHttpMessagesAsync(tokenParameters, null, cancellationToken).ConfigureAwait(false)) 78 | { 79 | return _result.Body; 80 | } 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /libraries/DirectLineClient.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Net.Http; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | public partial class DirectLineClient 10 | { 11 | /// 12 | /// Create a new instance of the DirectLineClient class 13 | /// 14 | /// Optional. The secret or token for the Direct Line site. If null, this setting is read from settings["DirectLineSecret"] 15 | /// Optional. The delegating handlers to add to the http client pipeline. 16 | public DirectLineClient(string secretOrToken = null, params DelegatingHandler[] handlers) 17 | : this(handlers) 18 | { 19 | this.Credentials = new DirectLineClientCredentials(secretOrToken); 20 | } 21 | 22 | /// 23 | /// Create a new instance of the DirectLineClient class 24 | /// 25 | /// Base URI for the Direct Line service 26 | /// Credentials for the Direct Line service 27 | /// /// Optional. The delegating handlers to add to the http client pipeline. 28 | public DirectLineClient(Uri baseUri, DirectLineClientCredentials credentials, params DelegatingHandler[] handlers) 29 | : this(baseUri, handlers) 30 | { 31 | this.Credentials = credentials; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libraries/DirectLineClientCredentials.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | #if FEATURE_SYSTEM_CONFIGURATION 6 | using System.Configuration; 7 | #endif 8 | using System.Net.Http; 9 | using System.Net.Http.Headers; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | using Microsoft.Rest; 13 | 14 | namespace Microsoft.Bot.Connector.DirectLine 15 | { 16 | /// 17 | /// Use credentials from AppSetting "DirectLineSecret" 18 | /// 19 | public class DirectLineClientCredentials : ServiceClientCredentials 20 | { 21 | #if FEATURE_SYSTEM_CONFIGURATION 22 | private static Lazy _secret = new Lazy(() => ConfigurationManager.AppSettings["DirectLineSecret"]); 23 | private static Lazy _endpoint = new Lazy(() => ConfigurationManager.AppSettings["DirectLineEndpoint"]); 24 | #else 25 | // .NET Core does not support System.Configuration API's. 26 | private static Lazy _secret = new Lazy(() => null); 27 | private static Lazy _endpoint = new Lazy(() => null); 28 | #endif 29 | 30 | public string Secret { get; private set; } 31 | 32 | public string Authorization { get; private set; } 33 | 34 | public string Endpoint { get; protected set; } 35 | 36 | /// 37 | /// Create a new instance of the DirectLineClientCredentials class 38 | /// 39 | /// default will come from Settings["DirectLineSecret"] 40 | public DirectLineClientCredentials(string secret = null, string endpoint = null) 41 | { 42 | this.Secret = secret ?? _secret.Value; 43 | this.Authorization = this.Secret; 44 | this.Endpoint = endpoint ?? _endpoint.Value ?? "https://directline.botframework.com/"; 45 | } 46 | 47 | /// 48 | /// Apply the credentials to the HTTP request. 49 | /// 50 | /// The HTTP request.Cancellation token. 51 | public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) 52 | { 53 | request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.Authorization); 54 | return base.ProcessHttpRequestAsync(request, cancellationToken); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /libraries/EntityEx.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Linq; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace Microsoft.Bot.Connector.DirectLine 13 | { 14 | public partial class Entity 15 | { 16 | [JsonExtensionData(ReadData = true, WriteData = true)] 17 | public JObject Properties { get; set; } 18 | 19 | /// 20 | /// Retrieve internal payload. 21 | /// 22 | /// 23 | /// 24 | public T GetAs() 25 | { 26 | return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(this)); 27 | } 28 | 29 | /// 30 | /// Set internal payload. 31 | /// 32 | /// 33 | /// 34 | public void SetAs(T obj) 35 | { 36 | var entity = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj)); 37 | this.Type = entity.Type; 38 | this.Properties = entity.Properties; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libraries/ErrorHandling.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using Microsoft.Bot.Connector.DirectLine; 6 | using Microsoft.Rest; 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | public static class ErrorHandling 11 | { 12 | public static ObjectT HandleError(this HttpOperationResponse result) 13 | { 14 | if (!result.Response.IsSuccessStatusCode) 15 | { 16 | ErrorResponse errorResponse = result.Body as ErrorResponse; 17 | throw new HttpOperationException(String.IsNullOrEmpty(errorResponse?.Error?.Message) ? result.Response.ReasonPhrase : errorResponse.Error.Message) 18 | { 19 | Request = result.Request.ForException(), 20 | Response = result.Response.ForException(), 21 | Body = result.Body 22 | }; 23 | } 24 | return (ObjectT)result.Body; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libraries/Extensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot.Streaming; 10 | using Microsoft.Bot.Streaming.Payloads; 11 | using Newtonsoft.Json; 12 | 13 | namespace Microsoft.Bot.Connector.DirectLine 14 | { 15 | internal static class Extensions 16 | { 17 | public static async Task ReadBodyAsJsonAsync(this ReceiveResponse response) 18 | { 19 | // The first stream attached to a ReceiveRequest is always the ReceiveRequest body. 20 | // Any additional streams must be defined within the body or they will not be 21 | // attached properly when processing activities. 22 | try 23 | { 24 | T returnValue = default(T); 25 | string streamContent = await response.ReadBodyAsStringAsync().ConfigureAwait(false); 26 | if (streamContent != null) 27 | { 28 | returnValue = JsonConvert.DeserializeObject(streamContent); 29 | } 30 | return returnValue; 31 | } 32 | catch (Exception) 33 | { 34 | throw; 35 | } 36 | } 37 | 38 | public static async Task ReadBodyAsStringAsync(this ReceiveResponse response) 39 | { 40 | // The first stream attached to a ReceiveRequest is always the ReceiveRequest body. 41 | // Any additional streams must be defined within the body or they will not be 42 | // attached properly when processing activities. 43 | try 44 | { 45 | var contentStream = response.Streams.FirstOrDefault(); 46 | if (contentStream != null) 47 | { 48 | return await ReadBuffer(contentStream).ConfigureAwait(false); 49 | } 50 | return null; 51 | } 52 | catch (Exception) 53 | { 54 | throw; 55 | } 56 | } 57 | 58 | private static async Task ReadBuffer(IContentStream contentStream) 59 | { 60 | var length = contentStream.Length ?? 100; 61 | StringBuilder outputBuilder = new StringBuilder(length); 62 | char[] c = new char[length]; 63 | int readCount = 0; 64 | using (var reader = new StreamReader(contentStream.Stream, Encoding.UTF8)) 65 | { 66 | do 67 | { 68 | readCount = await reader.ReadAsync(c, 0, c.Length); 69 | outputBuilder.Append(c, 0, readCount); 70 | } while (readCount > 0); 71 | } 72 | return outputBuilder.ToString(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /libraries/IActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Shared properties for all activities 11 | /// 12 | public interface IActivity 13 | { 14 | /// 15 | /// Activity type 16 | /// 17 | string Type { get; set; } 18 | 19 | /// 20 | /// Id for the activity 21 | /// 22 | string Id { get; set; } 23 | 24 | /// 25 | /// ServiceUrl 26 | /// 27 | string ServiceUrl { get; set; } 28 | 29 | /// 30 | /// UTC Time when message was sent 31 | /// 32 | DateTime? Timestamp { get; set; } 33 | 34 | /// 35 | /// Client Time when message was sent Ex: 2016-09-23T13:07:49.4714686-07:00 36 | /// 37 | DateTimeOffset? LocalTimestamp { get; set; } 38 | 39 | /// 40 | /// Channel this activity is associated with 41 | /// 42 | string ChannelId { get; set; } 43 | 44 | /// 45 | /// Sender address data 46 | /// 47 | ChannelAccount From { get; set; } 48 | 49 | /// 50 | /// Address for the conversation that this activity is associated with 51 | /// 52 | ConversationAccount Conversation { get; set; } 53 | 54 | /// 55 | /// Address that received the message 56 | /// 57 | ChannelAccount Recipient { get; set; } 58 | 59 | /// 60 | /// The original id this message is a response to 61 | /// 62 | string ReplyToId { get; set; } 63 | 64 | /// 65 | /// Channel specific payload 66 | /// 67 | /// 68 | /// Some channels will provide channel specific data. 69 | /// 70 | /// For a message originating in the channel it might provide the original native schema object for the channel. 71 | /// 72 | /// For a message coming into the channel it might accept a payload allowing you to create a "native" response for the channel. 73 | /// 74 | /// Example: 75 | /// * Email - The Email Channel will put the original Email metadata into the ChannelData object for outgoing messages, and will accept 76 | /// on incoming message a Subject property, and a HtmlBody which can contain Html. 77 | /// 78 | /// The channel data essentially allows a bot to have access to native functionality on a per channel basis. 79 | /// 80 | dynamic ChannelData { get; set; } 81 | 82 | /// 83 | /// Return IMessageActivity if this is a message activity, null otherwise 84 | /// 85 | IMessageActivity AsMessageActivity(); 86 | 87 | /// 88 | /// Return IContactRelationUpdateActivity if this is a contactRelationUpdate activity, null otherwise 89 | /// 90 | IContactRelationUpdateActivity AsContactRelationUpdateActivity(); 91 | 92 | /// 93 | /// Return IInstallationUpdateActivity if this is a installationUpdate activity, null otherwise 94 | /// 95 | IInstallationUpdateActivity AsInstallationUpdateActivity(); 96 | 97 | /// 98 | /// Return IConversationUpdateActivity if this is a conversationUpdate activity, null otherwise 99 | /// 100 | IConversationUpdateActivity AsConversationUpdateActivity(); 101 | 102 | /// 103 | /// Return ITypingActivity if this is a typing activity, null otherwise 104 | /// 105 | ITypingActivity AsTypingActivity(); 106 | 107 | /// 108 | /// Return IEndOfConversationActivity if this is an end-of-conversation activity, null otherwise 109 | /// 110 | IEndOfConversationActivity AsEndOfConversationActivity(); 111 | 112 | /// 113 | /// Returns IEventActivity if this is an event activity, null otherwise 114 | /// 115 | IEventActivity AsEventActivity(); 116 | 117 | /// 118 | /// Returns IInvokeActivity if this is an invoke activity, null otherwise 119 | /// 120 | IInvokeActivity AsInvokeActivity(); 121 | 122 | /// 123 | /// Returns IMessageUpdateActivity if this is a message update activity, null otherwise 124 | /// 125 | IMessageUpdateActivity AsMessageUpdateActivity(); 126 | 127 | /// 128 | /// Returns IMessageDeleteActivity if this is a message delete activity, null otherwise 129 | /// 130 | IMessageDeleteActivity AsMessageDeleteActivity(); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /libraries/IContactRelationUpdateActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Microsoft.Bot.Connector.DirectLine 11 | { 12 | /// 13 | /// Someone has updated their contact list 14 | /// 15 | public interface IContactRelationUpdateActivity : IActivity 16 | { 17 | 18 | /// 19 | /// Add|remove 20 | /// 21 | string Action { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libraries/IConversationUpdate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | /// 11 | /// The Properties of a conversation are different 12 | /// 13 | public interface IConversationUpdateActivity : IActivity 14 | { 15 | /// 16 | /// Array of address added 17 | /// 18 | IList MembersAdded { get; set; } 19 | 20 | /// 21 | /// Array of addresses removed 22 | /// 23 | IList MembersRemoved { get; set; } 24 | 25 | /// 26 | /// Conversations new topic name 27 | /// 28 | string TopicName { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /libraries/IEndOfConversationActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Conversation is ending, or a request to end the conversation 11 | /// 12 | public interface IEndOfConversationActivity : IActivity 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libraries/IEventActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Activity generated by external sources with open ended value payload 11 | /// 12 | public interface IEventActivity : IActivity 13 | { 14 | /// 15 | /// Open ended value 16 | /// 17 | object Value { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /libraries/IInstallationUpdateActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Microsoft.Bot.Connector.DirectLine 11 | { 12 | /// 13 | /// A bot was added or removed from a channel 14 | /// 15 | public interface IInstallationUpdateActivity : IActivity 16 | { 17 | /// 18 | /// Add|remove 19 | /// 20 | string Action { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libraries/IInvokeActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Synchronous request to invoke an operation 11 | /// 12 | public interface IInvokeActivity : IActivity 13 | { 14 | /// 15 | /// Name of the operation to invoke 16 | /// 17 | string Name { get; set; } 18 | 19 | /// 20 | /// Open-ended value 21 | /// 22 | object Value { get; set; } 23 | 24 | /// 25 | /// Reference to another conversation or activity 26 | /// 27 | ConversationReference RelatesTo { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libraries/IMessageActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | /// 11 | /// Someone has added a message to the conversation 12 | /// 13 | public interface IMessageActivity : IActivity 14 | { 15 | /// 16 | /// The language code of the Text field 17 | /// 18 | /// 19 | /// See https://msdn.microsoft.com/en-us/library/hh456380.aspx for a list of valid language codes 20 | /// 21 | string Locale { get; set; } 22 | 23 | /// 24 | /// Text for the message 25 | /// 26 | string Text { get; set; } 27 | 28 | /// 29 | /// Text for the message 30 | /// 31 | string Summary { get; set; } 32 | 33 | /// 34 | /// Format of text fields [plain|markdown] default:markdown 35 | /// 36 | string TextFormat { get; set; } 37 | 38 | /// 39 | /// AttachmentLayout - hint for how to deal with multiple attachments Values: [list|carousel] default:list 40 | /// 41 | string AttachmentLayout { get; set; } 42 | 43 | /// 44 | /// content attachemnts 45 | /// 46 | IList Attachments { get; set; } 47 | 48 | /// 49 | /// Entities 50 | /// Collection of objects which contain metadata about this activity 51 | /// 52 | IList Entities { get; set; } 53 | 54 | /// 55 | /// True if this activity has text, attachments, or channelData 56 | /// 57 | bool HasContent(); 58 | 59 | /// 60 | /// Get channeldata as typed structure 61 | /// 62 | /// type to use 63 | /// typed object or default(TypeT) 64 | TypeT GetChannelData(); 65 | 66 | /// 67 | /// Get mentions 68 | /// 69 | Mention[] GetMentions(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /libraries/IMessageDeleteActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Indicates a delete of an existing Message Activity 11 | /// 12 | public interface IMessageDeleteActivity : IActivity 13 | { 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /libraries/IMessageUpdateActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// An update to an existing Message Activity 11 | /// 12 | public interface IMessageUpdateActivity : IMessageActivity 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libraries/ITypingActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// The From address is typing 11 | /// 12 | public interface ITypingActivity : IActivity 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libraries/InputHints.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Indicates whether the bot is accepting, expecting, or ignoring input 11 | /// 12 | public static class InputHints 13 | { 14 | /// 15 | /// The sender is passively ready for input but is not waiting on a response. 16 | /// 17 | public const string AcceptingInput = "acceptingInput"; 18 | 19 | /// 20 | /// The sender is ignoring input. Bots may send this hint if they are actively processing a request and will ignore input 21 | /// from users until the request is complete. 22 | /// 23 | public const string IgnoringInput = "ignoringInput"; 24 | 25 | /// 26 | /// The sender is actively expecting a response from the user. 27 | /// 28 | public const string ExpectingInput = "expectingInput"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /libraries/InstallationUpdateActionTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | /// 10 | /// Action types valid for InstallationUpdate activities 11 | /// 12 | public static class InstallationUpdateActionTypes 13 | { 14 | /// 15 | /// Bot was added 16 | /// 17 | public const string Add = "add"; 18 | 19 | /// 20 | /// Bot was removed 21 | /// 22 | public const string Remove = "remove"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libraries/Microsoft.Bot.Connector.DirectLine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net462;net472 5 | 4.11.0-local 6 | $(LocalPackageVersion) 7 | $(ReleasePackageVersion) 8 | $(LocalPackageVersion) 9 | $(ReleasePackageVersion) 10 | 11 | 12 | 13 | Microsoft.Bot.Connector.DirectLine 14 | This library implements C# classes for using the Bot Framework Direct Line REST API 15 | Microsoft 16 | Microsoft 17 | https://bots.botframework.com/Client/Images/bot-framework-default-7.png 18 | 19 | 20 | 21 | $(SolutionDir)..\build\35MSSharedLib1024.snk 22 | true 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /libraries/Microsoft.Bot.Connector.DirectLine.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft.Bot.Connector.DirectLine 5 | Microsoft 6 | https://bots.botframework.com/Client/Images/bot-framework-default-7.png 7 | false 8 | This library implements C# classes for using the Bot Framework Direct Line REST API 9 | Client REST API library for Microsoft Bot Framework Connector Direct Line 10 | en-US 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /libraries/Microsoft.Bot.Connector.DirectLine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Connector.DirectLine", "Microsoft.Bot.Connector.DirectLine.csproj", "{8E3AA2C1-C5FA-4703-AA2C-A8E5654072E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8E3AA2C1-C5FA-4703-AA2C-A8E5654072E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8E3AA2C1-C5FA-4703-AA2C-A8E5654072E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8E3AA2C1-C5FA-4703-AA2C-A8E5654072E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8E3AA2C1-C5FA-4703-AA2C-A8E5654072E2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {27BE4BAD-138B-427A-9E04-8F104E62238E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /libraries/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | /*[assembly: AssemblyTitle("Microsoft.Bot.Connector.DirectLine")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("Microsoft Corporation")] 11 | [assembly: AssemblyProduct("Microsoft Bot Framework")] 12 | [assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | */ 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | //[assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | //[assembly: Guid("1e9d204f-4f89-4877-a018-3221c35b9118")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | //[assembly: AssemblyVersion("3.0.2")] 34 | 35 | // Uncomment to delay-sign 36 | //[assembly: AssemblyKeyFileAttribute(@"..\35MSSharedLib1024.snk")] 37 | //[assembly: AssemblyDelaySignAttribute(true)] 38 | -------------------------------------------------------------------------------- /libraries/Streaming/AttachmentStream.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Text; 8 | 9 | namespace Microsoft.Bot.Connector.DirectLine 10 | { 11 | public class AttachmentStream 12 | { 13 | public AttachmentStream(string contentType, Stream stream) 14 | { 15 | ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); 16 | ContentStream = stream ?? throw new ArgumentNullException(nameof(stream)); 17 | } 18 | 19 | public string ContentType { get; } 20 | 21 | public Stream ContentStream { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libraries/Streaming/DirectLineClient.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Net.Http; 6 | 7 | namespace Microsoft.Bot.Connector.DirectLine 8 | { 9 | public partial class DirectLineClient 10 | { 11 | partial void CustomInitialize() 12 | { 13 | this.StreamingConversations = new StreamingConversations(this); 14 | } 15 | 16 | /// 17 | /// Gets the IConversations. 18 | /// 19 | public virtual IStreamingConversations StreamingConversations { get; private set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libraries/Streaming/DirectLineRequestHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using Microsoft.Bot.Streaming; 11 | using Microsoft.Bot.Streaming.Payloads; 12 | using Microsoft.Extensions.Logging; 13 | using Newtonsoft.Json; 14 | 15 | namespace Microsoft.Bot.Connector.DirectLine 16 | { 17 | internal class DirectLineRequestHandler : RequestHandler 18 | { 19 | private readonly Action _receiveActivities; 20 | 21 | private readonly string _postActivitiesPath; 22 | 23 | public DirectLineRequestHandler(string conversationId, Action receiveActivities) 24 | { 25 | _receiveActivities = receiveActivities; 26 | _postActivitiesPath = $"/conversations/{conversationId}/activities"; 27 | } 28 | 29 | public override async Task ProcessRequestAsync(ReceiveRequest request, ILogger logger, object context = null, CancellationToken cancellationToken = default(CancellationToken)) 30 | { 31 | if (request.Verb == "POST" && request.Path == _postActivitiesPath) 32 | { 33 | var activitySet = await ReadOptionalBodyAsJson(request).ConfigureAwait(false); 34 | 35 | if (request.Streams.Count > 1) 36 | { 37 | var attachmentDictionary = request.Streams.Skip(1).ToDictionary(a => a.Id); 38 | int streamsMappedtoActivitiesCount = 0; 39 | foreach (var activity in activitySet.Activities) 40 | { 41 | if (activity.Attachments == null || activity.Attachments.Count == 0) 42 | { 43 | continue; 44 | } 45 | 46 | for (int i = 0; i < activity.Attachments.Count(); i++) 47 | { 48 | if (string.Equals(activity.Attachments[i].ContentType, "bf-stream", StringComparison.InvariantCultureIgnoreCase)) 49 | { 50 | var id = Guid.Parse(activity.Attachments[i].Content.ToString()); 51 | var stream = attachmentDictionary[id]; 52 | activity.Attachments[i] = new Attachment() { ContentType = stream.ContentType, Content = stream.Stream }; 53 | streamsMappedtoActivitiesCount++; 54 | } 55 | } 56 | 57 | if (streamsMappedtoActivitiesCount == request.Streams.Count - 1) 58 | { 59 | break; 60 | } 61 | } 62 | } 63 | 64 | _receiveActivities(activitySet); 65 | return StreamingResponse.OK(); 66 | } 67 | return StreamingResponse.NotFound(); 68 | } 69 | 70 | private static async Task ReadOptionalBodyAsJson(ReceiveRequest request) 71 | { 72 | // The first stream attached to a ReceiveRequest is always the ReceiveRequest body. 73 | // Any additional streams must be defined within the body or they will not be 74 | // attached properly when processing activities. 75 | var contentStream = request.Streams.FirstOrDefault(); 76 | if (contentStream != null) 77 | { 78 | var contentString = await ReadBuffer(contentStream).ConfigureAwait(false); 79 | return JsonConvert.DeserializeObject(contentString); 80 | } 81 | return default(T); 82 | } 83 | 84 | private static async Task ReadBuffer(IContentStream contentStream) 85 | { 86 | var length = contentStream.Length ?? 100; 87 | StringBuilder outputBuilder = new StringBuilder(length); 88 | char[] c = new char[length]; 89 | int readCount = 0; 90 | using (var reader = new StreamReader(contentStream.Stream, Encoding.UTF8)) 91 | { 92 | do 93 | { 94 | readCount = await reader.ReadAsync(c, 0, c.Length); 95 | outputBuilder.Append(c, 0, readCount); 96 | } while (readCount > 0); 97 | } 98 | return outputBuilder.ToString(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /libraries/Streaming/IStreamingConversations.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 5 | // Changes may cause incorrect behavior and will be lost if the code is 6 | // regenerated. 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | using System; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | using Microsoft.Bot.Streaming.Transport; 14 | 15 | /// 16 | /// Conversations operations. 17 | /// 18 | public partial interface IStreamingConversations 19 | { 20 | /// 21 | /// A property to determine if the StreamingConversations is connected or not 22 | /// 23 | bool IsConnected { get; } 24 | 25 | /// 26 | /// An event that is signalled whenever the StreamingConversations becomes disconnected 27 | /// 28 | event DisconnectedEventHandler Disconnected; 29 | 30 | /// 31 | /// Connects the StreamingConversations class to a service using the DirectLineClient's endpoint and credential value 32 | /// This method takes a callback, receiveActivities, which is invoked whenever DirectLine needs to send Activities 33 | /// from the bot back to the client 34 | /// 35 | /// The conversationId that will be used for this connection. 36 | /// A callback that is invoked whenever Activities are sent back to the client 37 | /// Cancellation Token 38 | /// 39 | Task ConnectAsync( 40 | string conversationId, 41 | Action receiveActivities, 42 | CancellationToken cancellationToken = default(CancellationToken)); 43 | 44 | /// 45 | /// Disconnects the StreamingConversations class from the service 46 | /// 47 | void Disconnect(); 48 | 49 | /// 50 | /// Starts a conversation with the bot. This method will signal to the Direct Line instance that user's who are added 51 | /// to the conversation will trigger ConversationUpdate Activities to be sent to the bot 52 | /// 53 | /// Optional configuration parameters about the conversation 54 | /// Cancellation Token 55 | /// 56 | Task StartConversationAsync( 57 | TokenParameters tokenParameters = null, 58 | CancellationToken cancellationToken = default(CancellationToken)); 59 | 60 | /// 61 | /// Reconnects a conversation with the bot. After calling this method, user's who are added to the conversation 62 | /// will NOT cause ConversationUpdate messages to be sent to the bot 63 | /// 64 | /// The conversationId to reconnect to. 65 | /// Activity watermark 66 | /// Cancellation Token 67 | /// 68 | Task ReconnectToConversationAsync( 69 | string conversationId, 70 | string watermark = null, 71 | CancellationToken cancellationToken = default(CancellationToken)); 72 | 73 | /// 74 | /// Sends an UpdateActivity to the bot 75 | /// 76 | /// The conversation id 77 | /// The id of the activity to update 78 | /// The updated activity 79 | /// Cancellation Token 80 | /// 81 | Task UpdateActivityAsync( 82 | string conversationId, 83 | string activityId, 84 | Activity activity, 85 | CancellationToken cancellationToken = default(CancellationToken)); 86 | 87 | /// 88 | /// Sends an activity to the bot 89 | /// 90 | /// The conversationId 91 | /// The activity to send 92 | /// Cancellation Token 93 | /// An optional set of streams (attachments) that should accompany the Activity 94 | /// 95 | Task PostActivityAsync( 96 | string conversationId, 97 | Activity activity, 98 | CancellationToken cancellationToken = default(CancellationToken), 99 | params AttachmentStream[] attachmentStreams); 100 | 101 | /// 102 | /// Sends a set of streaming attachments to the bot 103 | /// 104 | /// The conversationId 105 | /// The userId associated with sending these attachments 106 | /// Cancellation Token 107 | /// A set of streams (attachments) that should accompany the Activity 108 | /// 109 | Task UploadAttachmentsAsync( 110 | string conversationId, 111 | string userId, 112 | CancellationToken cancellationToken = default(CancellationToken), 113 | params AttachmentStream[] attachmentStreams); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /libraries/Streaming/OperationException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Microsoft.Bot.Connector.DirectLine 9 | { 10 | /// 11 | /// Thrown when a streaming operation had an error 12 | /// 13 | public class OperationException : Exception 14 | { 15 | /// 16 | /// The status code 17 | /// 18 | public int StatusCode { get; set; } 19 | 20 | /// 21 | /// The body of the error 22 | /// 23 | public object Body { get; set; } 24 | 25 | /// 26 | /// Creates an OperationException 27 | /// 28 | public OperationException(string message, int statusCode, object body) : 29 | base(message) 30 | { 31 | StatusCode = statusCode; 32 | Body = body; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /libraries/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectLineBot", "DirectLineBot\DirectLineBot.csproj", "{A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectLineSampleClient", "DirectLineClient\DirectLineSampleClient.csproj", "{10935995-5C58-438B-B5F0-FA94BEA2667F}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "README", "README", "{24EE8FDE-6FB7-4352-AAFA-F53D188003D8}" 11 | ProjectSection(SolutionItems) = preProject 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/AdapterWithErrorHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v4.6.2 5 | 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 7 | using Microsoft.Bot.Builder.TraceExtensions; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace DirectLineBot 12 | { 13 | public class AdapterWithErrorHandler : BotFrameworkHttpAdapter 14 | { 15 | public AdapterWithErrorHandler(IConfiguration configuration, ILogger logger) 16 | : base(configuration, logger) 17 | { 18 | OnTurnError = async (turnContext, exception) => 19 | { 20 | // Log any leaked exception from the application. 21 | logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}"); 22 | 23 | // Send a message to the user 24 | await turnContext.SendActivityAsync("The bot encountered an error or bug."); 25 | await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); 26 | 27 | // Send a trace activity, which will be displayed in the Bot Framework Emulator 28 | await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError"); 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/Bots/EchoBot.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using System.Collections.Generic; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot.Builder; 10 | using Microsoft.Bot.Schema; 11 | 12 | namespace DirectLineBot.Bots 13 | { 14 | public class EchoBot : ActivityHandler 15 | { 16 | protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) 17 | { 18 | string replyText = null; 19 | Attachment attachment = null; 20 | 21 | switch (turnContext.Activity.Text.ToLower()) 22 | { 23 | case "show me a hero card": 24 | replyText = $"Sample message with a HeroCard attachment"; 25 | 26 | attachment = new HeroCard 27 | { 28 | Title = "Sample Hero Card", 29 | Text = "Displayed in the DirectLine client" 30 | }.ToAttachment(); 31 | 32 | break; 33 | case "send me a botframework image": 34 | replyText = $"Sample message with an Image attachment"; 35 | 36 | attachment = new Attachment() 37 | { 38 | ContentType = "image/png", 39 | ContentUrl = "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png", 40 | }; 41 | 42 | break; 43 | default: 44 | replyText = $"You said '{turnContext.Activity.Text}'"; 45 | break; 46 | } 47 | 48 | var reply = MessageFactory.Text(replyText, replyText); 49 | if(attachment != null) 50 | { 51 | reply.Attachments.Add(attachment); 52 | } 53 | await turnContext.SendActivityAsync(reply, cancellationToken); 54 | } 55 | 56 | protected override async Task OnMembersAddedAsync(IList membersAdded, ITurnContext turnContext, CancellationToken cancellationToken) 57 | { 58 | var welcomeText = "Hello and welcome!"; 59 | foreach (var member in membersAdded) 60 | { 61 | if (member.Id != turnContext.Activity.Recipient.Id) 62 | { 63 | await turnContext.SendActivityAsync(MessageFactory.Text(welcomeText, welcomeText), cancellationToken); 64 | } 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/Controllers/BotController.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Bot.Builder; 9 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 10 | 11 | namespace DirectLineBot.Controllers 12 | { 13 | // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot 14 | // implementation at runtime. Multiple different IBot implementations running at different endpoints can be 15 | // achieved by specifying a more specific type for the bot constructor argument. 16 | [Route("api/messages")] 17 | [ApiController] 18 | public class BotController : ControllerBase 19 | { 20 | private readonly IBotFrameworkHttpAdapter Adapter; 21 | private readonly IBot Bot; 22 | 23 | public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) 24 | { 25 | Adapter = adapter; 26 | Bot = bot; 27 | } 28 | 29 | [HttpPost, HttpGet] 30 | public async Task PostAsync() 31 | { 32 | // Delegate the processing of the HTTP POST to the adapter. 33 | // The adapter will invoke the bot. 34 | await Adapter.ProcessAsync(Request, Response, Bot); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/DirectLineBot.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | latest 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Always 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | 9 | namespace DirectLineBot 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | CreateWebHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 19 | WebHost.CreateDefaultBuilder(args) 20 | .UseStartup(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Bot.Builder; 10 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 11 | using Microsoft.Extensions.Configuration; 12 | using Microsoft.Extensions.DependencyInjection; 13 | 14 | using DirectLineBot.Bots; 15 | 16 | namespace DirectLineBot 17 | { 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | } 24 | 25 | public IConfiguration Configuration { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 31 | 32 | // Create the Bot Framework Adapter with error handling enabled. 33 | services.AddSingleton(); 34 | 35 | // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. 36 | services.AddTransient(); 37 | } 38 | 39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | else 47 | { 48 | app.UseHsts(); 49 | } 50 | 51 | app.UseDefaultFiles(); 52 | app.UseStaticFiles(); 53 | app.UseWebSockets(); 54 | //app.UseHttpsRedirection(); 55 | app.UseMvc(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineBot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MicrosoftAppId": "", 3 | "MicrosoftAppPassword": "" 4 | } 5 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/DirectLineSampleClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {10935995-5C58-438B-B5F0-FA94BEA2667F} 8 | Exe 9 | Properties 10 | DirectLineSampleClient 11 | DirectLineSampleClient 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Microsoft.Bot.Connector.DirectLine.3.0.1\lib\net45\Microsoft.Bot.Connector.DirectLine.dll 38 | 39 | 40 | ..\packages\Microsoft.Rest.ClientRuntime.2.3.4\lib\net45\Microsoft.Rest.ClientRuntime.dll 41 | True 42 | 43 | 44 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/Models/DirectLineCardContent.cs: -------------------------------------------------------------------------------- 1 | namespace DirectLineSampleClient.Models 2 | { 3 | public class DirectLineCardContent 4 | { 5 | public string Text { get; set; } 6 | 7 | public string Title { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/Program.cs: -------------------------------------------------------------------------------- 1 | namespace DirectLineSampleClient 2 | { 3 | using System; 4 | using System.Configuration; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using Microsoft.Bot.Connector.DirectLine; 9 | using Models; 10 | using Newtonsoft.Json; 11 | 12 | public class Program 13 | { 14 | private static string directLineSecret = ConfigurationManager.AppSettings["DirectLineSecret"]; 15 | private static string botId = ConfigurationManager.AppSettings["BotId"]; 16 | private static string fromUser = "DirectLineSampleClientUser"; 17 | 18 | public static void Main(string[] args) 19 | { 20 | StartBotConversation().Wait(); 21 | } 22 | 23 | private static async Task StartBotConversation() 24 | { 25 | // if you are using a region-specific endpoint, change the uri and uncomment the code 26 | // var directLineUri = "https://directline.botframework.com/"; // endpoint in Azure Public Cloud 27 | // DirectLineClient client = new DirectLineClient(new Uri(directLineUri), new DirectLineClientCredentials(directLineSecret)); 28 | 29 | DirectLineClient client = new DirectLineClient(directLineSecret); 30 | 31 | var conversation = await client.Conversations.StartConversationAsync(); 32 | 33 | new System.Threading.Thread(async () => await ReadBotMessagesAsync(client, conversation.ConversationId)).Start(); 34 | 35 | Console.Write("Command> "); 36 | 37 | while (true) 38 | { 39 | string input = Console.ReadLine().Trim(); 40 | 41 | if (input.ToLower() == "exit") 42 | { 43 | break; 44 | } 45 | else 46 | { 47 | if (input.Length > 0) 48 | { 49 | Activity userMessage = new Activity 50 | { 51 | From = new ChannelAccount(fromUser), 52 | Text = input, 53 | Type = ActivityTypes.Message 54 | }; 55 | 56 | await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage); 57 | } 58 | } 59 | } 60 | } 61 | 62 | private static async Task ReadBotMessagesAsync(DirectLineClient client, string conversationId) 63 | { 64 | string watermark = null; 65 | 66 | while (true) 67 | { 68 | var activitySet = await client.Conversations.GetActivitiesAsync(conversationId, watermark); 69 | watermark = activitySet?.Watermark; 70 | 71 | var activities = from x in activitySet.Activities 72 | where x.From.Id == botId 73 | select x; 74 | 75 | foreach (Activity activity in activities) 76 | { 77 | Console.WriteLine(activity.Text); 78 | 79 | if (activity.Attachments != null) 80 | { 81 | foreach (Attachment attachment in activity.Attachments) 82 | { 83 | switch (attachment.ContentType) 84 | { 85 | case "application/vnd.microsoft.card.hero": 86 | RenderHeroCard(attachment); 87 | break; 88 | 89 | case "image/png": 90 | Console.WriteLine($"Opening the requested image '{attachment.ContentUrl}'"); 91 | 92 | Process.Start(attachment.ContentUrl); 93 | break; 94 | } 95 | } 96 | } 97 | 98 | Console.Write("Command> "); 99 | } 100 | 101 | await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); 102 | } 103 | } 104 | 105 | private static void RenderHeroCard(Attachment attachment) 106 | { 107 | const int Width = 70; 108 | Func contentLine = (content) => string.Format($"{{0, -{Width}}}", string.Format("{0," + ((Width + content.Length) / 2).ToString() + "}", content)); 109 | 110 | var heroCard = JsonConvert.DeserializeObject(attachment.Content.ToString()); 111 | 112 | if (heroCard != null) 113 | { 114 | Console.WriteLine("/{0}", new string('*', Width + 1)); 115 | Console.WriteLine("*{0}*", contentLine(heroCard.Title)); 116 | Console.WriteLine("*{0}*", new string(' ', Width)); 117 | Console.WriteLine("*{0}*", contentLine(heroCard.Text)); 118 | Console.WriteLine("{0}/", new string('*', Width + 1)); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DirectLineSampleClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DirectLineSampleClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("10935995-5c58-438b-b5f0-fa94bea2667f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/core-DirectLine/DirectLineClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/core-DirectLine/README.md: -------------------------------------------------------------------------------- 1 | # Direct Line Bot Sample 2 | 3 | A sample bot and a custom client communicating to each other using the Direct Line API. 4 | 5 | ### Prerequisites 6 | 7 | The minimum prerequisites to run this sample are: 8 | * The latest update of Visual Studio 2017. You can download the community version [here](http://www.visualstudio.com) for free. 9 | * The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://emulator.botframework.com/). Please refer to [this documentation article](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) to know more about the Bot Framework Emulator. 10 | * Register your bot with the Microsoft Bot Framework. Please refer to [this](https://docs.microsoft.com/en-us/bot-framework/portal-register-bot) for the instructions. Once you complete the registration, update the [Bot's appsettings.json](DirectLineBot/appsettings.json) file with the registered config values (MicrosoftAppId and MicrosoftAppPassword) 11 | 12 | #### Direct Line API 13 | Credentials for the Direct Line API must be obtained from the Bot Channels Registration in the Azure portal, and will only allow the caller to connect to the bot for which they were generated. 14 | In the Bot Framework developer portal, enable Direct Line in the channels list and then, configure the Direct Line secret and update its value in the [client's App.config](DirectLineClient/App.config#L4-L5) file alongside with the Bot Id. Make sure that the checkbox for version 3.0 is checked. Refer to [this](https://docs.microsoft.com/en-us/bot-framework/portal-configure-channels) for more information on how to configure channels. 15 | 16 | ![Configure Direct Line](images/outcome-configure.png) 17 | 18 | #### Publish 19 | Also, in order to be able to run and test this sample you must [deploy your bot, for example to Azure](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli). Alternatively, you can use [Ngrok to interact with your local bot in the cloud](https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/). 20 | 21 | ### Code Highlights 22 | 23 | The Direct Line API is a simple REST API for connecting directly to a single bot. This API is intended for developers writing their own client applications, web chat controls, or mobile apps that will talk to their bot. The [Direct Line v3.0 Nuget package](https://www.nuget.org/packages/Microsoft.Bot.Connector.DirectLine) simplifies access to the underlying REST API. 24 | 25 | Each conversation on the Direct Line channel must be explicitly started using the `DirectLineClient.Conversations.StartConversationAsync`. 26 | Check out the client's [Program.cs](DirectLineClient/Program.cs#L25-L27) class which creates a new `DirectLineClient` and starts a new conversation. 27 | 28 | 29 | ````C# 30 | // if you are using a region-specific endpoint, change the uri and uncomment the code 31 | // var directLineUri = "https://directline.botframework.com/"; // endpoint in Azure Public Cloud 32 | // DirectLineClient client = new DirectLineClient(new Uri(directLineUri), new DirectLineClientCredentials(directLineSecret)); 33 | 34 | DirectLineClient client = new DirectLineClient(directLineSecret); 35 | 36 | var conversation = await client.Conversations.StartConversationAsync(); 37 | ```` 38 | 39 | User messages are sent to the Bot using the Direct Line Client `Conversations.PostActivityAsync` method using the `ConversationId` generated in the previous step. 40 | 41 | ````C# 42 | while (true) 43 | { 44 | string input = Console.ReadLine().Trim(); 45 | 46 | if (input.ToLower() == "exit") 47 | { 48 | break; 49 | } 50 | else 51 | { 52 | if (input.Length > 0) 53 | { 54 | Activity userMessage = new Activity 55 | { 56 | From = new ChannelAccount(fromUser), 57 | Text = input, 58 | Type = ActivityTypes.Message 59 | }; 60 | 61 | await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage); 62 | } 63 | } 64 | } 65 | ```` 66 | 67 | Messages from the Bot are continually polled from the API in another Thread in the `ReadBotMessagesAsync` method. Check out the [Program.cs](DirectLineClient/Program.cs#L64-L69) usage of `GetActivitiesAsync` method which retrieves conversation messages newer than the stored watermark. Activities are then filtered to receive messages from the Bot only. 68 | 69 | ````C# 70 | var activitySet = await client.Conversations.GetActivitiesAsync(conversationId, watermark); 71 | watermark = activitySet?.Watermark; 72 | 73 | var activities = from x in activitySet.Activities 74 | where x.From.Id == botId 75 | select x; 76 | ```` 77 | 78 | DirectLine v3.0 has support for Attachments (see [Add media attachments to messages](https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-media-attachments) for more information about attachments). Check out the `ReadBotMessagesAsync` method in [Program.cs](DirectLineClient/Program.cs#L75-L92) to see how the Attachments are retrieved and rendered appropriately based on their type. 79 | 80 | 81 | ````C# 82 | if (activity.Attachments != null) 83 | { 84 | foreach (Attachment attachment in activity.Attachments) 85 | { 86 | switch (attachment.ContentType) 87 | { 88 | case "application/vnd.microsoft.card.hero": 89 | RenderHeroCard(attachment); 90 | break; 91 | 92 | case "image/png": 93 | Console.WriteLine($"Opening the requested image '{attachment.ContentUrl}'"); 94 | 95 | Process.Start(attachment.ContentUrl); 96 | break; 97 | } 98 | } 99 | } 100 | ```` 101 | 102 | 103 | ### Outcome 104 | 105 | To run the sample, you'll need to run both Bot and Client apps. 106 | * Running Bot app 107 | 1. In the Visual Studio Solution Explorer window, right click on the **DirectLineBot** project. 108 | 2. In the contextual menu, select Debug, then Start New Instance and wait for the _Web application_ to start. 109 | * Running Client app 110 | 1. In the Visual Studio Solution Explorer window, right click on the **DirectLineSampleClient** project. 111 | 2. In the contextual menu, select Debug, then Start New Instance and wait for the _Console application_ to start. 112 | 113 | To test the Attachments type `show me a hero card` or `send me a botframework image` and you should see the following outcome. 114 | 115 | ![Sample Outcome](images/outcome.png) 116 | 117 | ### More Information 118 | 119 | To get more information about how to get started in Bot Builder for .NET and Conversations please review the following resources: 120 | * [Bot Builder for .NET](https://docs.microsoft.com/en-us/bot-framework/dotnet/) 121 | * [Bot Framework FAQ](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-resources-bot-framework-faq#i-have-a-communication-channel-id-like-to-be-configurable-with-bot-framework-can-i-work-with-microsoft-to-do-that) 122 | * [Direct Line API - v3.0](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-overview/) 123 | * [Direct Line v3.0 Nuget package](https://www.nuget.org/packages/Microsoft.Bot.Connector.DirectLine/) 124 | * [Add media attachments to messages](https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-media-attachments) 125 | * [Bot Framework Emulator](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) 126 | -------------------------------------------------------------------------------- /samples/core-DirectLine/images/outcome-configure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/BotFramework-DirectLine-DotNet/7c4504777e057124e0ab0bd40e1a1891babbf35e/samples/core-DirectLine/images/outcome-configure.png -------------------------------------------------------------------------------- /samples/core-DirectLine/images/outcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/BotFramework-DirectLine-DotNet/7c4504777e057124e0ab0bd40e1a1891babbf35e/samples/core-DirectLine/images/outcome.png -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectLineBot", "DirectLineBot\DirectLineBot.csproj", "{A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectLineSampleClient", "DirectLineClient\DirectLineSampleClient.csproj", "{10935995-5C58-438B-B5F0-FA94BEA2667F}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "README", "README", "{24EE8FDE-6FB7-4352-AAFA-F53D188003D8}" 11 | ProjectSection(SolutionItems) = preProject 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {10935995-5C58-438B-B5F0-FA94BEA2667F}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/AdapterWithErrorHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v4.6.2 5 | 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 7 | using Microsoft.Bot.Builder.TraceExtensions; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace DirectLineBot 12 | { 13 | public class AdapterWithErrorHandler : BotFrameworkHttpAdapter 14 | { 15 | public AdapterWithErrorHandler(IConfiguration configuration, ILogger logger) 16 | : base(configuration, logger) 17 | { 18 | OnTurnError = async (turnContext, exception) => 19 | { 20 | // Log any leaked exception from the application. 21 | logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}"); 22 | 23 | // Send a message to the user 24 | await turnContext.SendActivityAsync("The bot encountered an error or bug."); 25 | await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); 26 | 27 | // Send a trace activity, which will be displayed in the Bot Framework Emulator 28 | await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError"); 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/Bots/EchoBot.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using System.Collections.Generic; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot.Builder; 10 | using Microsoft.Bot.Schema; 11 | 12 | namespace DirectLineBot.Bots 13 | { 14 | public class EchoBot : ActivityHandler 15 | { 16 | protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) 17 | { 18 | string replyText = null; 19 | Attachment attachment = null; 20 | 21 | switch (turnContext.Activity.Text.ToLower()) 22 | { 23 | case "show me a hero card": 24 | replyText = $"Sample message with a HeroCard attachment"; 25 | 26 | attachment = new HeroCard 27 | { 28 | Title = "Sample Hero Card", 29 | Text = "Displayed in the DirectLine client" 30 | }.ToAttachment(); 31 | 32 | break; 33 | case "send me a botframework image": 34 | replyText = $"Sample message with an Image attachment"; 35 | 36 | attachment = new Attachment() 37 | { 38 | ContentType = "image/png", 39 | ContentUrl = "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png", 40 | }; 41 | 42 | break; 43 | default: 44 | replyText = $"You said '{turnContext.Activity.Text}'"; 45 | break; 46 | } 47 | 48 | var reply = MessageFactory.Text(replyText, replyText); 49 | if(attachment != null) 50 | { 51 | reply.Attachments.Add(attachment); 52 | } 53 | await turnContext.SendActivityAsync(reply, cancellationToken); 54 | } 55 | 56 | protected override async Task OnMembersAddedAsync(IList membersAdded, ITurnContext turnContext, CancellationToken cancellationToken) 57 | { 58 | var welcomeText = "Hello and welcome!"; 59 | foreach (var member in membersAdded) 60 | { 61 | if (member.Id != turnContext.Activity.Recipient.Id) 62 | { 63 | await turnContext.SendActivityAsync(MessageFactory.Text(welcomeText, welcomeText), cancellationToken); 64 | } 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/Controllers/BotController.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Bot.Builder; 9 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 10 | 11 | namespace DirectLineBot.Controllers 12 | { 13 | // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot 14 | // implementation at runtime. Multiple different IBot implementations running at different endpoints can be 15 | // achieved by specifying a more specific type for the bot constructor argument. 16 | [Route("api/messages")] 17 | [ApiController] 18 | public class BotController : ControllerBase 19 | { 20 | private readonly IBotFrameworkHttpAdapter Adapter; 21 | private readonly IBot Bot; 22 | 23 | public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) 24 | { 25 | Adapter = adapter; 26 | Bot = bot; 27 | } 28 | 29 | [HttpPost, HttpGet] 30 | public async Task PostAsync() 31 | { 32 | // Delegate the processing of the HTTP POST to the adapter. 33 | // The adapter will invoke the bot. 34 | await Adapter.ProcessAsync(Request, Response, Bot); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/DirectLineBot.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | latest 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Always 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | 9 | namespace DirectLineBot 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | CreateWebHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 19 | WebHost.CreateDefaultBuilder(args) 20 | .UseStartup(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | // 4 | // Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2 5 | 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Bot.Builder; 10 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 11 | using Microsoft.Extensions.Configuration; 12 | using Microsoft.Extensions.DependencyInjection; 13 | 14 | using DirectLineBot.Bots; 15 | 16 | namespace DirectLineBot 17 | { 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | } 24 | 25 | public IConfiguration Configuration { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 31 | 32 | // Create the Bot Framework Adapter with error handling enabled. 33 | services.AddSingleton(); 34 | 35 | // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. 36 | services.AddTransient(); 37 | } 38 | 39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | else 47 | { 48 | app.UseHsts(); 49 | } 50 | 51 | app.UseDefaultFiles(); 52 | app.UseStaticFiles(); 53 | app.UseWebSockets(); 54 | //app.UseHttpsRedirection(); 55 | app.UseMvc(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineBot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MicrosoftAppId": "", 3 | "MicrosoftAppPassword": "" 4 | } 5 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineClient/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineClient/DirectLineSampleClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {10935995-5C58-438B-B5F0-FA94BEA2667F} 8 | Exe 9 | Properties 10 | DirectLineSampleClient 11 | DirectLineSampleClient 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Microsoft.Bot.Connector.DirectLine.3.0.1\lib\net45\Microsoft.Bot.Connector.DirectLine.dll 38 | True 39 | 40 | 41 | ..\packages\Microsoft.Rest.ClientRuntime.2.3.2\lib\net45\Microsoft.Rest.ClientRuntime.dll 42 | True 43 | 44 | 45 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 46 | True 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | ..\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll 62 | True 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineClient/Program.cs: -------------------------------------------------------------------------------- 1 | namespace DirectLineSampleClient 2 | { 3 | using System; 4 | using System.Configuration; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using Microsoft.Bot.Connector.DirectLine; 9 | using Newtonsoft.Json; 10 | using System.Threading; 11 | using System.Text; 12 | using WebSocketSharp; 13 | 14 | public class Program 15 | { 16 | private static string directLineSecret = ConfigurationManager.AppSettings["DirectLineSecret"]; 17 | private static string botId = ConfigurationManager.AppSettings["BotId"]; 18 | 19 | // fromUser is the field that identifies which user is sending activities to the Direct Line service. 20 | // Because this value is created and sent within your Direct Line client, your bot should not 21 | // trust the value for any security-sensitive operations. Instead, have the user log in and 22 | // store any sign-in tokens against the Conversation or Private state fields. Those fields 23 | // are secured by the conversation ID, which is protected with a signature. 24 | private static string fromUser = "DirectLineSampleClientUser"; 25 | 26 | public static void Main(string[] args) 27 | { 28 | StartBotConversation().Wait(); 29 | } 30 | 31 | private static async Task StartBotConversation() 32 | { 33 | // if you are using a region-specific endpoint, change the uri and uncomment the code 34 | // var directLineUri = "https://directline.botframework.com/"; // endpoint in Azure Public Cloud 35 | // var tokenResponse = await new DirectLineClient(new Uri(directLineUri), new DirectLineClientCredentials(directLineSecret)).Tokens.GenerateTokenForNewConversationAsync(); 36 | // var directLineClient = new DirectLineClient(new Uri(directLineUri), new DirectLineClientCredentials(tokenResponse.Token)); 37 | 38 | // Obtain a token using the Direct Line secret 39 | var tokenResponse = await new DirectLineClient(directLineSecret).Tokens.GenerateTokenForNewConversationAsync(); 40 | 41 | // Use token to create conversation 42 | var directLineClient = new DirectLineClient(tokenResponse.Token); 43 | var conversation = await directLineClient.Conversations.StartConversationAsync(); 44 | 45 | using (var webSocketClient = new WebSocket(conversation.StreamUrl)) 46 | { 47 | webSocketClient.OnMessage += WebSocketClient_OnMessage; 48 | // You have to specify TLS version to 1.2 or connection will be failed in handshake. 49 | webSocketClient.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12; 50 | webSocketClient.Connect(); 51 | 52 | while (true) 53 | { 54 | string input = Console.ReadLine().Trim(); 55 | 56 | if (input.ToLower() == "exit") 57 | { 58 | break; 59 | } 60 | else 61 | { 62 | if (input.Length > 0) 63 | { 64 | Activity userMessage = new Activity 65 | { 66 | From = new ChannelAccount(fromUser), 67 | Text = input, 68 | Type = ActivityTypes.Message 69 | }; 70 | 71 | await directLineClient.Conversations.PostActivityAsync(conversation.ConversationId, userMessage); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | private static void WebSocketClient_OnMessage(object sender, MessageEventArgs e) 79 | { 80 | // Occasionally, the Direct Line service sends an empty message as a liveness ping. Ignore these messages. 81 | if (string.IsNullOrWhiteSpace(e.Data)) 82 | { 83 | return; 84 | } 85 | 86 | var activitySet = JsonConvert.DeserializeObject(e.Data); 87 | var activities = from x in activitySet.Activities 88 | where x.From.Id == botId 89 | select x; 90 | 91 | foreach (Activity activity in activities) 92 | { 93 | Console.WriteLine(activity.Text); 94 | 95 | if (activity.Attachments != null) 96 | { 97 | foreach (Attachment attachment in activity.Attachments) 98 | { 99 | switch (attachment.ContentType) 100 | { 101 | case "application/vnd.microsoft.card.hero": 102 | RenderHeroCard(attachment); 103 | break; 104 | 105 | case "image/png": 106 | Console.WriteLine($"Opening the requested image '{attachment.ContentUrl}'"); 107 | 108 | Process.Start(attachment.ContentUrl); 109 | break; 110 | } 111 | } 112 | } 113 | 114 | Console.Write("Command> "); 115 | } 116 | } 117 | 118 | private static void RenderHeroCard(Attachment attachment) 119 | { 120 | const int Width = 70; 121 | Func contentLine = (content) => string.Format($"{{0, -{Width}}}", string.Format("{0," + ((Width + content.Length) / 2).ToString() + "}", content)); 122 | 123 | var heroCard = JsonConvert.DeserializeObject(attachment.Content.ToString()); 124 | 125 | if (heroCard != null) 126 | { 127 | Console.WriteLine("/{0}", new string('*', Width + 1)); 128 | Console.WriteLine("*{0}*", contentLine(heroCard.Title)); 129 | Console.WriteLine("*{0}*", new string(' ', Width)); 130 | Console.WriteLine("*{0}*", contentLine(heroCard.Text)); 131 | Console.WriteLine("{0}/", new string('*', Width + 1)); 132 | } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DirectLineSampleClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DirectLineSampleClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("10935995-5c58-438b-b5f0-fa94bea2667f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/DirectLineClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/README.md: -------------------------------------------------------------------------------- 1 | # Direct Line Bot Sample (using client WebSockets) 2 | 3 | A sample bot and a custom client communicating with each other using the Direct Line API and WebSockets. 4 | 5 | ### Prerequisites 6 | 7 | The minimum prerequisites to run this sample are: 8 | * The latest update of Visual Studio 2017. You can download the community version [here](http://www.visualstudio.com) for free. 9 | * The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://emulator.botframework.com/). Please refer to [this documentation article](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) to know more about the Bot Framework Emulator. 10 | * Register your bot with the Microsoft Bot Framework. Please refer to [this](https://docs.microsoft.com/en-us/bot-framework/portal-register-bot) for the instructions. Once you complete the registration, update the [Bot's appsettings.json](DirectLineBot/appsettings.json) file with the registered config values (MicrosoftAppId and MicrosoftAppPassword) 11 | 12 | #### Direct Line API 13 | Credentials for the Direct Line API must be obtained from the Bot Channels Registration in the Azure portal, and will only allow the caller to connect to the bot for which they were generated. 14 | In the Bot Framework developer portal, enable Direct Line in the channels list and then, configure the Direct Line secret and update its value in the [client's App.config](DirectLineClient/App.config#L4-L5) file alongside with the Bot Id. Make sure that the checkbox for version 3.0 is checked. Refer to [this](https://docs.microsoft.com/en-us/bot-framework/portal-configure-channels) for more information on how to configure channels. 15 | 16 | ![Configure Direct Line](images/outcome-configure.png) 17 | 18 | #### Publish 19 | Also, in order to be able to run and test this sample you must [deploy your bot, for example to Azure](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli). Alternatively, you can use [Ngrok to interact with your local bot in the cloud](https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/). 20 | 21 | ### Code Highlights 22 | 23 | The Direct Line API is a simple REST API for connecting directly to a single bot. This API is intended for developers writing their own client applications, web chat controls, or mobile apps that will talk to their bot. The [Direct Line v3.0 Nuget package](https://www.nuget.org/packages/Microsoft.Bot.Connector.DirectLine) simplifies access to the underlying REST API. 24 | 25 | Each conversation on the Direct Line channel must be explicitly started using the `DirectLineClient.Conversations.StartConversationAsync`. 26 | Check out the client's [Program.cs](DirectLineClient/Program.cs#L25-L27) class which creates a new `DirectLineClient` and starts a new conversation. 27 | 28 | You'll see that we are using the Direct Line secret to [obtain a token](DirectLineClient/Program.cs#L34). This step is optional, but prevents clients from accessing conversations they aren't participating in. 29 | 30 | ````C# 31 | // Obtain a token using the Direct Line secret 32 | var tokenResponse = await new DirectLineClient(directLineSecret).Tokens.GenerateTokenForNewConversationAsync(); 33 | 34 | // Use token to create conversation 35 | var directLineClient = new DirectLineClient(tokenResponse.Token); 36 | var conversation = await directLineClient.Conversations.StartConversationAsync(); 37 | ```` 38 | 39 | User messages are sent to the Bot using the Direct Line Client `Conversations.PostActivityAsync` method using the `ConversationId` generated in the previous step. 40 | 41 | ````C# 42 | while (true) 43 | { 44 | string input = Console.ReadLine().Trim(); 45 | 46 | if (input.ToLower() == "exit") 47 | { 48 | break; 49 | } 50 | else 51 | { 52 | if (input.Length > 0) 53 | { 54 | Activity userMessage = new Activity 55 | { 56 | From = new ChannelAccount(fromUser), 57 | Text = input, 58 | Type = ActivityTypes.Message 59 | }; 60 | 61 | await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage); 62 | } 63 | } 64 | } 65 | ```` 66 | 67 | Messages from the Bot are being received using WebSocket protocol. When the conversation was created a `streamUrl` is also returned and it will be the target for the WebSocket connection. Check out the client's WebSocket initialization in [Program.cs](DirectLineClient/Program.cs#L40-L43). 68 | 69 | > Note: In this project we use [websocket-sharp](https://github.com/sta/websocket-sharp) to implement the receiver client but this functionality can be implemented according to the needs of the solution. 70 | 71 | ````C# 72 | using (var webSocketClient = new WebSocket(conversation.StreamUrl)) 73 | { 74 | webSocketClient.OnMessage += WebSocketClient_OnMessage; 75 | webSocketClient.Connect(); 76 | ```` 77 | 78 | We use the [WebSocketClient_OnMessage](DirectLineClient/Program.cs#L71) method to handle the OnMessage event of the `webSocketClient` witch occurs when the WebSocket receives a message. 79 | 80 | ````C# 81 | private static void WebSocketClient_OnMessage(object sender, MessageEventArgs e) 82 | { 83 | var activitySet = JsonConvert.DeserializeObject(e.Data); 84 | var activities = from x in activitySet.Activities 85 | where x.From.Id == botId 86 | select x; 87 | ```` 88 | 89 | Direct Line v3.0 has support for Attachments (see [Add media attachments to messages](https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-media-attachments) for more information about attachments). Check out the `WebSocketClient_OnMessage` method in [Program.cs](DirectLineClient/Program.cs#L88-L105) to see how the Attachments are retrieved and rendered appropriately based on their type. 90 | 91 | 92 | ````C# 93 | if (activity.Attachments != null) 94 | { 95 | foreach (Attachment attachment in activity.Attachments) 96 | { 97 | switch (attachment.ContentType) 98 | { 99 | case "application/vnd.microsoft.card.hero": 100 | RenderHeroCard(attachment); 101 | break; 102 | 103 | case "image/png": 104 | Console.WriteLine($"Opening the requested image '{attachment.ContentUrl}'"); 105 | 106 | Process.Start(attachment.ContentUrl); 107 | break; 108 | } 109 | } 110 | } 111 | ```` 112 | 113 | 114 | ### Outcome 115 | 116 | To run the sample, you'll need to run both Bot and Client apps. 117 | * Running Bot app 118 | 1. In the Visual Studio Solution Explorer window, right click on the **DirectLineBot** project. 119 | 2. In the contextual menu, select Debug, then Start New Instance and wait for the _Web application_ to start. 120 | * Running Client app 121 | 1. In the Visual Studio Solution Explorer window, right click on the **DirectLineSampleClient** project. 122 | 2. In the contextual menu, select Debug, then Start New Instance and wait for the _Console application_ to start. 123 | 124 | To test the Attachments type `show me a hero card` or `send me a botframework image` and you should see the following outcome. 125 | 126 | ![Sample Outcome](images/outcome.png) 127 | 128 | ### More Information 129 | 130 | To get more information about how to get started in Bot Builder for .NET and Conversations please review the following resources: 131 | * [Bot Builder for .NET](https://docs.microsoft.com/en-us/bot-framework/dotnet/) 132 | * [Bot Framework FAQ](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-resources-bot-framework-faq#i-have-a-communication-channel-id-like-to-be-configurable-with-bot-framework-can-i-work-with-microsoft-to-do-that) 133 | * [Direct Line API - v3.0](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-overview/) 134 | * [Direct Line v3.0 Nuget package](https://www.nuget.org/packages/Microsoft.Bot.Connector.DirectLine/) 135 | * [Add media attachments to messages](https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-media-attachments) 136 | * [Bot Framework Emulator](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) 137 | 138 | -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/images/outcome-configure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/BotFramework-DirectLine-DotNet/7c4504777e057124e0ab0bd40e1a1891babbf35e/samples/core-DirectLineWebSockets/images/outcome-configure.png -------------------------------------------------------------------------------- /samples/core-DirectLineWebSockets/images/outcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/BotFramework-DirectLine-DotNet/7c4504777e057124e0ab0bd40e1a1891babbf35e/samples/core-DirectLineWebSockets/images/outcome.png --------------------------------------------------------------------------------