Giter Club home page Giter Club logo

line-bot-sdk-dotnet-sample's Introduction

line-bot-sdk-dotnet-sample

GitHub license Twitter URL

This project contains a sample of how line-bot-sdk-dotnet can be used in a .NET web application.

What do I need to use this sample in a bot channel?

To use this sample in a bot channel you will need the following:

  • Visual Studio 2017
  • Docker
  • Azure account

The sample project also works when you run the resulting Docker container on another platform than Azure but because of the integration with Azure inside Visual Studio you can run this sample very quickly inside Azure.

How can I use this sample in a bot channel?

The first step is cloning the repository:

Microsoft Windows [Version 10.0.16299.309]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\line-bot-sdk-dotnet-sample>git clone https://github.com/dlemstra/line-bot-sdk-dotnet-sample.git.
Cloning into '.'...
remote: Counting objects: 29, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 29 (delta 5), reused 29 (delta 5), pack-reused 0
Unpacking objects: 100% (29/29), done.
Checking connectivity... done.

After cloning this project you will need to open the solution in the root of the project: LineBotSample.sln. This project requires Docker to be installed. When the projected is opened with Visual Studio 2017 you will receive an examplantion on how to install Docker when this is not yet installed.

The next step is modifying the file appsettings.json in the LineBotSample project. This file has the following content:

{
  "LineConfiguration": {
    "ChannelAccessToken": "YourChannelAccessToken",
    "ChannelSecret": "YourChannelSecret"
  }
}

The values that need to entered in the LineConfiguration block can be found on the settings page of the bot channel:

settings page

The next step is to publish the LineBotSample to Azure. This can be done with a right-click on the LineBotSample project:

publish project

This will open the following dialog:

publish target

On this dialog the option App Service Linux should be picked and the publish button can be pressed that will open the following dialog:

create app service

When the create button on that dialog is pressed the App Service will be created in Azure and the following dialog will be shown:

publish summary

On this page the Site URL should be copied and pasted in the appsettings.json. http should be changed into https and /resources/ should be added to the end url.

{
  "LineBotSampleConfiguration": {
    "ResourcesUrl": "https://linebotsample20180402094740.azurewebsites.net/resources/"
  }
}

After setting this value the Publish button in the last dialog should be pressed to update the App Service.

And the last step is setting the WebHook in the channel but to see what is happening when the webhook is verified it is wise to enable diagnostics logs open a Cloud Shell in Azure:

diagnostics logs

In the Cloud Shell the command below needs to be entered. The value for --name should be the name of the App Service, and -g the name of the Resource Group.

dirk@Azure:~$ az webapp log tail --name LineBotSample20180402094740 -g cloud-shell-storage-westeurope

The WebHook should also be set on the settings page of the channel.

webhook

After clicking on Update the Verify button will become visible.

verify

Pressing this button will send a message to the bot and this should be shown in the Cloud Shell.

cloud shell

This bot now only handles LineEventType.Message and responds to 3 messages.

  • When the message contains ping the bot will reply with pong.
  • When the message contains user the bot will reply with a message the contains information of the user.
  • When the message contains logo the bot will reply with an image that is the logo of this project.

The code for the event handler can be found in src/LineBotSample/EventHandlers/MessageEventHandler.cs. Feel free to modify this sample and play around with it. This project is also open to PR's with extra samples.

line-bot-sdk-dotnet-sample's People

Contributors

dlemstra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.