再度LINE APIを活用したサービスを書くことになったので、自分メモ。
LINEの応対用メッセージフォーマットは下記。
テキストメッセージ
一番ベーシックな返信方法
{
"type": "text",
"text": "Hello, world"
}
スタンプメッセージ
スタンプで返したい場合
{
"type": "sticker",
"packageId": "1",
"stickerId": "1"
}
イメージメッセージ
スタンプを返したい場合
{
"type": "image",
"originalContentUrl": "https://example.com/original.jpg",
"previewImageUrl": "https://example.com/preview.jpg"
}
ビデオメッセージ
ビデオコンテンツを返したい場合
{
"type": "video",
"originalContentUrl": "https://example.com/original.mp4",
"previewImageUrl": "https://example.com/preview.jpg"
}
オーディオメッセージ
オーディオで返したい場合
{
"type": "audio",
"originalContentUrl": "https://example.com/original.m4a",
"duration": 60000
}
ロケーションメッセージ
ロケーションを返したい場合
{
"type": "location",
"title": "my location",
"address": "〒150-0002 東京都渋谷区渋谷2丁目21−1",
"latitude": 35.65910807942215,
"longitude": 139.70372892916203
}
イメージマップメッセージ
イメージマップを返したい場合
{
"type": "imagemap",
"baseUrl": "https://example.com/bot/images/rm001",
"altText": "This is an imagemap",
"baseSize": {
"width": 1040,
"height": 1040
},
"video": {
"originalContentUrl": "https://example.com/video.mp4",
"previewImageUrl": "https://example.com/video_preview.jpg",
"area": {
"x": 0,
"y": 0,
"width": 1040,
"height": 585
},
"externalLink": {
"linkUri": "https://example.com/see_more.html",
"label": "See More"
}
},
"actions": [
{
"type": "uri",
"linkUri": "https://example.com/",
"area": {
"x": 0,
"y": 586,
"width": 520,
"height": 454
}
},
{
"type": "message",
"text": "Hello",
"area": {
"x": 520,
"y": 586,
"width": 520,
"height": 454
}
}
]
}
テンプレートメッセージ
ボタンありテンプレートで返す場合
{
"type": "template",
"altText": "This is a buttons template",
"template": {
"type": "buttons",
"thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
"imageAspectRatio": "rectangle",
"imageSize": "cover",
"imageBackgroundColor": "#FFFFFF",
"title": "Menu",
"text": "Please select",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=123"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=123"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
}
]
}
}
Yes/No 確認メッセージ
はい、いいえで確認する場合
{
"type": "template",
"altText": "this is a confirm template",
"template": {
"type": "confirm",
"text": "Are you sure?",
"actions": [
{
"type": "message",
"label": "Yes",
"text": "yes"
},
{
"type": "message",
"label": "No",
"text": "no"
}
]
}
}
カールセルメッセージ
カールセルの情報を返したい場合
{
"type": "template",
"altText": "this is a carousel template",
"template": {
"type": "carousel",
"columns": [
{
"thumbnailImageUrl": "https://example.com/bot/images/item1.jpg",
"imageBackgroundColor": "#FFFFFF",
"title": "this is menu",
"text": "description",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=111"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=111"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/111"
}
]
},
{
"thumbnailImageUrl": "https://example.com/bot/images/item2.jpg",
"imageBackgroundColor": "#000000",
"title": "this is menu",
"text": "description",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/222"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=222"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=222"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/222"
}
]
}
],
"imageAspectRatio": "rectangle",
"imageSize": "cover"
}
}
イメージカールセル
イメージカールセルで返したいとき
{
"type": "template",
"altText": "this is a image carousel template",
"template": {
"type": "image_carousel",
"columns": [
{
"imageUrl": "https://example.com/bot/images/item1.jpg",
"action": {
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=111"
}
},
{
"imageUrl": "https://example.com/bot/images/item2.jpg",
"action": {
"type": "message",
"label": "Yes",
"text": "yes"
}
},
{
"imageUrl": "https://example.com/bot/images/item3.jpg",
"action": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/222"
}
}
]
}
}
フレックスメッセージ
フレックスメッセージで返したいとき
{
"type": "flex",
"altText": "this is a flex message",
"contents": {
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "hello"
},
{
"type": "text",
"text": "world"
}
]
}
}
}
参照