Get real original character as a LINE chatbot for any stores to increase their sales. You can make the chatbot easily for Japan popular chat tool LINE. It can effect your commerce. Watson Assistant API can help building your LINE chatbot application.
How to build this application *now just in Japanese
We have lots of chat/text tools such kind of WhatsApp, WeChat, Slack, Facebook, Messenger, and more... And currently in Japan LINE is most popular chat service/application. Get real original character as a LINE chatbot for any stores to increase their sales. You can make the chatbot easily for Japan popular chat tool LINE. It can effect your commerce. Watson Assistant API can help building your LINE chatbot application.
Select Watson Assistant from IBM Cloud Catalog.
Fill down Service Name, and select Region(US South is recomended), Org, and Space. You can use it as Light Plan, and then press the create button.
Get credencial information when Assistant API created. If the credencial has not yet created automaticaly, you can generate new credencial on Service Credencial Menu. Note API Endpoint URL, USER, and PASSWORD. ※No need this operation if Node-RED will be on IBM Cloud and bind with Assistant API.
This is a workspace for Watson Assistant can train definitions and flows of chat talks for chatbot application. It has a unique ID which will be used for an application to call API. Select Assistant API you created.
Launch Watson Assistant Tool. Press the Launch Button.
Click the create button, open new flow window, but this time we use "flow import function". Click the Arrow Icon next Create button.
You can download the flow definision file Press the Coose a file button to select JSON file.
Complete for preparing IBM Cloud Side. Do you want to work more? Sorry, that's all. If you want to custom it more, you can modify it or create new workspace.
Create Node-RED on IBM Cloud. Select "Node-RED Starter" from Starter Kit category on Catalog. And then you can establish your Node-RED.
Bind Watson Assistant API you created to your Node-RED. Select your Node-RED App.
Create new Connect from Connection Menu.
Click Connect button (appear with mouse over). Please select default authentication.
Please wait a moment for re-staging process. After complete the process you can access your Node-RED Flow Editor. It is very simple to meke Node-RED application foe this application. The completed flow view is below;
Create server-side application which is called from LINE webhook, on Node-RED. It will call Watson Assistant API. You can download completed flow definition
The first node "http in" is for configration URL to access this Node-RED application. Already set the URL "/line_hook" on the flow you downloaded.
Node-RED is just Node.js application, so the application you will create on it is also Node.js application. IBM Cloud alocated unique URL on your application. This application now you created on Node-RED has the URL below;
https://<Your Node-RED App Name>.mybluemix.net/<Path you set on "http in node">/
例)https://fillgapapp01-nodered01.mybluemix.net/line_hook/
The first Function node "getText" is for keeping LINE API reply token.
//flowへ格納
flow.set(“replyToken”,msg.payload.events[0].replyToken);
return msg;
You can access the value saved the flow anytime anywhere.
First Change node, it is for replacing the talking sentence from LINE to accept by Watson Assistant API.
Call Watson Assistant API. Place your Assistant Workspace ID. You already bind Assistant to Node-RED, so no need to config credentials.
Second Change node, it is for replace parameter from the response of Assistant to "msg.payload.optext".
Second Function node "createReplyMessage", make talking sentence for replying to LINE App.
var post_request = {
“headers”: {
“content-type”: “application/json; charset=UTF-8”,
“Authorization”: “ Bearer “ + “{ACCESS TOKEN FROM LINE}”
},
“payload”: {
“replyToken”: flow.get(“replyToken”),
“messages”: [
{
“type”: “text”,
“text”: msg.payload.optext + “ฅ^•ﻌ•^ฅ”
}
]
}
};
return post_request;
Already set parameters for replying talking sentence as POST request, on your Node-RED flow you downloaded.
- Access Token generated by LINE (describing is below)
- Reply Token on flow
- Sentence text on text (with ascii art cat character )
Finally, set reply URL for LINE on http request node.
https://api.line.me/v2/bot/message/reply
You can login LINE developers with your LINE account which can be created on your smartphone LINE app.
Login LINE developers here.
And then, click "Create Channel" button on Messaging API tile.
Config any informations which is needed for the channel. The each values are below;
- App Icon Image: less than 3MB, JPEG/PNG/GIF/BMP
- App Name: 20 charactors or less
- App Description: 500 charactors or less
- Plan: Developer Trial
- Industries: Any
- EMail Address: Any
Agree the terms of service and then press the Agreement button.
Check the two check box for these agreements, and press create button.
Click the tile of the channel you created.
You should work just two.
- Generate Channel access token (long-lived)
- Set Webhook URL
Generate Channel access token After the operation, you need to place this token on your Node-RED Function node. Press the issue button twice.
Config these settings below;
- Use Webhooks -> Enabled
- Webhook URL -> Your Node-RED app URL
- Auto-reply messages -> Disabled
Congrats! You finaly did it!
Add this chatbot to your LINE friends with QR Code. You can find QR Code bottom of LINE developers basic information page. Mobile LINE App: Add Friend -> QR Code
I believe you got your chatbot on your smartphone LINE app. Good luck modify this application more!