uiuifree.com

- サイト制作のノウハウと最適化を目指して-

2020.6.24【LINE Messaging API】アクション別にWebhookの中身をまとめてみた

【LINE Messaging API】アクション別にWebhookの中身をまとめてみた

LINE Messaging APIのWebhookで何が渡ってくるのか、まとまってるドキュメント見つけれませんでしたので参考程度に置いておきます。

メッセージアクション

action
'action' => [
    "type" => "message",
    "text" => "こんにちは",
],
webhook
 [events] => Array
        (
            [0] => Array
                (
                    [type] => message
                    [replyToken] => ab05a459169b403ca81bc9d0c31d2b9f
                    [source] => Array
                        (
                            [userId] => U379389a9740600000000000
                            [type] => user
                        )

                    [timestamp] => 1592966556528
                    [mode] => active
                    [message] => Array
                        (
                            [type] => text
                            [id] => 12199254320940
                            [text] => こんにちは
                        )

                )

        )

ポストバックアクション

action
 'action' => [
    "type" => "postback",
    "label" => "favorite",
    "data" => "favorite",
]
webhook
 [events] => Array
        (
            [0] => Array
                (
                    [type] => postback
                    [replyToken] => 232913ead49c462f947000797a9703d3
                    [source] => Array
                        (
                            [userId] => U379389a9740600000000000
                            [type] => user
                        )

                    [timestamp] => 1592960247920
                    [mode] => active
                    [postback] => Array
                        (
                            [data] => favorite
                        )

                )

        )

URIアクション

action
'action' => [
    "type" => "uri",
    "label" => "View details",
    "uri" => "http://example.com/page/222",
],
webhook
Webhookは発生しない

日時選択アクション

action
'action' => [
     "type" => "datetimepicker",
    "label" => "Select date",
    "data" => "storeId=12345",
    "mode" => "datetime",
    "initial" => "2017-12-25t00:00",
    "max" => "2018-01-24t23:59",
    "min" => "2017-12-25t00:00",
],
webhook
 [events] => Array
        (
            [0] => Array
                (
                    [type] => postback
                    [replyToken] => 9c05d2548f2642668f6c9ef2ec393b3f
                    [source] => Array
                        (
                            [userId] => U379389a9740600000000000
                            [type] => user
                        )

                    [timestamp] => 1592961195753
                    [mode] => active
                    [postback] => Array
                        (
                            [data] => storeId=12345
                            [params] => Array
                                (
                                    [datetime] => 2018-01-02T00:00
                                )
                        )
                )
        )

位置情報

action
"action" => [
    "type" => "location",
    "label" => "Send location"
]
webhook
    [events] => Array
        (
            [0] => Array
                (
                    [type] => message
                    [replyToken] => 0e67f4c79860483f88e5ccd81edf0470
                    [source] => Array
                        (
                            [userId] => U379389a9740600000000000
                            [type] => user
                        )

                    [timestamp] => 1592963212565
                    [mode] => active
                    [message] => Array
                        (
                            [type] => location
                            [id] => 12199022196894
                            [address] => 日本、〒105-0011 東京都港区芝公園2丁目12−12
                            [latitude] => 35.653784430911
                            [longitude] => 139.75120805204
                        )

                )

        )

カメラアクション(QuickReply専用)

action
"action" => [
    "type" => "camera",
    "label" => "Camera"
]
webhook
  [events] => Array
        (
            [0] => Array
                (
                    [type] => message
                    [replyToken] => 34b1e104bd8c45c98809777cdeed1c0d
                    [source] => Array
                        (
                            [userId] => U379389a9740600000000000
                            [type] => user
                        )

                    [timestamp] => 1592965973587
                    [mode] => active
                    [message] => Array
                        (
                            [type] => image
                            [id] => 12199213144621
                            [contentProvider] => Array
                                (
                                    [type] => line
                                )

                        )

                )

        )

PROFILE

このサイトを運営してるuiuifreeです。
渋谷のベンチャー企業で2年ほど新規事業を担当した後にフリーランスエンジニアにキャリア転換。
求人サイトの開発が多くエンジニア/看護師/保育士などの分野でサイトを運営しています。

アウトプット中の技術

リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック (Theory in practice)