A good UI primarily focuses on attracting large numbers of users and any good UI designer aims to achieve user satisfaction with a user-friendly design. In this blog, we will learn how to show carousels and location map in SUSI line bot to make UI better and easy to use. We can show web search result from SUSI in form of text responses in line bot but it doesn’t follow design rule as it is not a good approach to show more text in constricted space. Users deem such a layout as less attractive. In SUSI webchat, location is returned with a map which looks more promising to users as illustrated below:
Web search is returned as carousels and is viewable as:
We can implement web search in line by sending an array of text responses. We can do this with the code below:
for (var i = 0; i < 5; i++) {
msg[i] = "";
msg[i] = {
type: 'text',
text: 'text to be sent here'
}
}
return client.replyMessage(event.replyToken, msg);
If we send web search using text response it looks messy, a user will not like it that much as it is difficult for a user to read and understand a lot of text in one place. You can see it in the screenshot below:
To make it better looking we will implement carousels for web search in SUSI line bot. Carousels are tiles that can be scrolled horizontally to show rich content. We can implement carousels using this code:
for (var i = 1; i < 4; i++) {
title = 'title of carousel';
query = title;
msg = 'description of carousel here';
link = 'link to be opened here';
if (title.length >= 40) {
title = title.substring(0, 36);
title = title + "...";
}
if (msg.length >= 60) {
msg = msg.substring(0, 56);
msg = msg + "...";
}
carousel[i] = {
"title": title,
"text": msg,
"actions": [{
"type": "uri",
"label": "View detail",
"uri": link
},
{
"type": "message",
"label": "Ask SUSI again",
"text": query
}
]
};
}
In above code, we are checking the length of title and description because line API has a limit for the title up to 40 characters and description up to 60 characters. If limit exceeds we then trim the title or description accordingly and use it. Next, we assign title, description, and link to be opened in action to carousel so that we can use it in below code.
const answer = [{
type: 'text',
text: ans
},
{
"type": "template",
"altText": "this is a carousel template",
"template": {
"type": "carousel",
"columns": [
carousel[1],
carousel[2],
carousel[3]
]
}
}
]
return client.replyMessage(event.replyToken, answer);
Above code shows an array names answer in which we have added carousels that we have created in last code. After implementing this web search will look like this:
This UI looks neat and easy to read and users will like this. Ask SUSI again will send the title of the carousel to SUSI. To show location map on SUSI line bot just like it is shown on SUSI webchat we will follow this code:
const answer = [{
type: 'text',
text: ans
},
{
"type": "location",
"title": "name of the place here",
"address": address,
"latitude": latitude of location here,
"longitude": longitude of location here
}
]
return client.replyMessage(event.replyToken, answer);
We will send a location type message which will include latitude and longitude of the location so that Line bot can show location using map. After implementing location type response it will look like this:
On clicking on this location it will open a map inside line app on which we will see a pointer pointing at the location that we have provided.
If you want to learn more about line messaging API refer to this https://devdocs.line.me/en/#messaging-api
Resources
https://devdocs.line.me/en/#messaging-api
You must be logged in to post a comment.