Boost LINE Bot development productivity by using LINE Client Simulator
Tags: line, simulator, bot, visualstudiocode
Published: 2018-02-08 05:20:39

---
title: Boost LINE Bot development productivity by using LINE Client Simulator
published: true
description: Boost LINE Bot development productivity by using LINE Client Simulator
tags: Line,Simulator,bot,VisualStudioCode
cover_image: https://msdnshared.blob.core.windows.net/media/2017/12/basic_thumb.gif
---

Productivity is a key as a developer, and that's why I use IDE such as Visual Studio. When it comes to LINE Bot development, the bottle neck is that I need to use physical device to test the bot.

# LINE Client for Windows and MacOS

Of course LINE releases its client application for non-mobile platforms, but it is limited when I interact with bot.

![image](https://msdnshared.blob.core.windows.net/media/2017/12/image_thumb78.png)
# Simulator

Now what? Well, I develop a simulator to solve the issue.

npm: https://www.npmjs.com/package/line-simulator
GitHub: https://github.com/kenakamu/LINESimulator

To try this out, of course you need your own LINE bot. You can refer to my [previous article](https://dev.to/kenakamu/c-line-bot-development-with-azure-function-for-cross-platform-3jlp) to build one if you don't have any, but it works with any LINE bot regardless of the language you use.

# Update LINE Bot to use the simulator

To use the simulator, you need to let your bot knows it. The following steps are example of C# function app. If you use other languages, please refer to [README in GitHub](https://github.com/kenakamu/Linesimulator#how-to-specify-the-simulator-url-for-bot-application)

1\. Open run.cs

2\. Pass simulator address to LineMessageClinet constructor.

```csharp
static HttpTriggerFunction()
{
    lineMessagingClient = new LineMessagingClient(
        Environment.GetEnvironmentVariable("ChannelAccessToken"),  
        "http://localhost:8080");
    var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me"));
    sp.ConnectionLeaseTimeout = 60 * 1000;
}
```

3\. run ```dotnet build``` in integrated terminal.

![image](http://msdnshared.blob.core.windows.net/media/2017/12/image_thumb284.png)

4\. move to .\bin\Debug\netstandard2.0\ and run ```func host start``` to run the function.

![image](https://msdnshared.blob.core.windows.net/media/2017/12/image_thumb285.png)

5\. Confirm it is running without any error.

![image](https://msdnshared.blob.core.windows.net/media/2017/12/image_thumb286.png)

6\. Enter F5 and attach to dotnet.exe


# Use simulator

1\. Run the following command to install the simulator

```shell
npm install -g line-simulator
```

2\. Then, run the following command to run it.

```shell
line-simulator
```

3\. You see the connect screen. Enter necessary information and click Connect. You can get the keys or user Id from LINE Developer Portal. 

![image](https://msdnshared.blob.core.windows.net/media/2017/12/image_thumb287.png)

4\. Once connected, you can see the simulator. Use chat bar to talk to your bot.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/basic.gif"><img title="basic" alt="basic" src="https://msdnshared.blob.core.windows.net/media/2017/12/basic_thumb.gif" /></a>

5\. You can debug as you want, then.

Check out [GitHub README(https://github.com/kenakamu/Linesimulator#how-to-use-the-simulator) for other features.

# Concept

The purpose of the simulator is to help developer to quickly debug the bot, thus I didn't implement features which is not related to bot development such as real sticker or make phone call. Use your physical device for final test anyways.

# Summary

Personally, I am quite happy to use it when I develop a bot. But I still need to work on to improve it. Any feedback or collaboration is highly appreciated!

Ken