การเปลี่ยน richmenu


ใช้โปรแกรม postman ช่วยในการทำ




ขั้นตอน
1.เราต้องสร้าง richmenu default ไว้ก่อน สร้างตามปกติใน admin-official

จากนั้นใน line bot designer ช่วยออกแบบ ซึ่งทำได้หลายแบบ




ถ้าเรากำหนดว่าเป็น default เวลาเปลี่ยนกลับมาเป็น deafault ก็คือเมนูนี้



2.สร้าง richmenu อันใหม่ แล้วยิง curl เผื่อให้ได้ richmenu id   โดย copy json จาก bot designer
post  https://api.line.me/v2/bot/richmenu

header authorizatoion Bearer line_token
content-type Application/json

Body raw -> json

----------------
{
  "size": {
    "width": 2500,
    "height": 1686
  },
  "selected": true,
  "name": "เมนูไอเดีย",
  "chatBarText": "ไอเดีย",
  "areas": [
    {
      "bounds": {
        "x": 173,
        "y": 960,
        "width": 370,
        "height": 193
      },
      "action": {
        "type": "uri",
        "uri": "line://app/1618004827-XGoGywdm"
      }
    },
    {
      "bounds": {
        "x": 1934,
        "y": 968,
        "width": 396,
        "height": 157
      },
      "action": {
        "type": "message",
        "text": "วันพระ"
      }
    },
    {
      "bounds": {
        "x": 393,
        "y": 494,
        "width": 387,
        "height": 153
      },
      "action": {
        "type": "uri",
        "uri": "line://app/1618004827-2qzP13qj"
      }
    },
    {
      "bounds": {
        "x": 1057,
        "y": 235,
        "width": 379,
        "height": 175
      },
      "action": {
        "type": "uri",
        "uri": "line://app/1618004827-VBnGmLEv"
      }
    },
    {
      "bounds": {
        "x": 1699,
        "y": 472,
        "width": 380,
        "height": 171
      },
      "action": {
        "type": "message",
        "text": "วันพระ"
      }
    }
  ]
}
------------
กด send แล้วจะได้

{
    "richMenuId": "richmenu-24b745e53386753b3e1e9b941a57856c"
}

3.อัพโหลดรูปขึ้นไปใน richmenu id ใหม่ที่สร้าง  ขนาดไม่เกิน 200 kb
post   https://api.line.me/v2/bot/richmenu/richmenu-24b745e53386753b3e1e9b941a57856c/content

authorization bearer line_token
content/type image/jpeg

binalry browse รูป




ตัวอย่างรูป


4. เรียกใช้ richmenu id ด้วย curl
post https://api.line.me/v2/bot/user/all/richmenu/richmenu-24b745e53386753b3e1e9b941a57856c

header authorization Bearer line_token


5. ถ้าอยากรู้ว่ามี richmenu id อะไรบ้างที่เราสร้าง ให้ใช้คำสั่งข้างล่างนี้


curl -v -X GET https://api.line.me/v2/bot/richmenu/list \
-H 'Authorization: Bearer {channel access token}'


6.ถ้าอยากกลับมาค่าเดิมล่ะทำงั้ย

curl -v -X GET https://api.line.me/v2/bot/user/all/richmenu \
-H 'Authorization: Bearer {channel access token}'

ที่มา https://developers.line.me/en/docs/messaging-api/using-rich-menus/

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

การทำ cloud iot ด้วย thingsboard ไว้ใช้เองครับ

การประยุกต์ใช้ line notify ในการแจ้งปัญหาการใช้งาน สำหรับ php

Send message to line when server down with python Line api (มอนิเตอร์ server แจ้งเตือนผ่าน Line)