Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MauticのWebhookでできること / Mautic Integration Using...

MauticのWebhookでできること / Mautic Integration Using Webhooks

https://mauticon.mautic.org/ja

Webhookについてのおさらい
各ベンダーのWebhook対応状況のシェア
Webhookのテストツールのご紹介
Mauticで利用可能なWebhookアクション
Webhookの作成方法
安全にWebhookを利用する方法
サンプルコードの実行例

More Decks by アクイアジャパン Acquia Japan

Other Decks in Programming

Transcript

  1. • 1991೥10݄29೔ ੜ·Ε • ಠཱܥιϑτ΢ΣΞ։ൃձࣾͰιϑτ΢ΣΞΤϯδχΞ • ͷͪΤόϯδΣϦετͱͯ͠ϓϩμΫτͷܒ໤׆ಈ • 2019೥8݄ ΞΫΠΞʹδϣΠϯ

    • ΢ΣϒαΠτͷίϯςϯπͷ
 ٕज़຋༁΍ϩʔΧϥΠζΛ୲౰ Ruby / Rails / Web API / Docker / AWS ϥʔϝϯ / εΠʔπ / Ωϟϯϓ൧ / ొࢁ Profile ΞΫΠΞδϟύϯ ؙࢁͻ͔Δ ςΫχΧϧτϥϯεϨʔλʔ
  2. Web APIͷ৔߹ Mautic mymautic.com Your App yourapp.com ᶃMauticʹAPIϦΫΤετΛૹ৴ GET https://mymautic.com/api/contacts

    ᶄMautic͕ίϯλΫτ৘ใΛฦ٫ {“contacts”: “ίϯλΫτ৘ใ”} ͍͍Α ίϯλΫτ৘ใ ͪΐ͏͍ͩ
  3. Webhookͷ৔߹ Mautic mymautic.com Your App yourapp.com ᶃYour AppͷΤϯυϙΠϯτʹ WebhookϖΠϩʔυΛૹ৴ POST

    https://yourapp.com/webhook {“contacts”: “ίϯλΫτ৘ใ”} {“success”: “true”} ίϯλΫτ৘ใ͕ߋ ৽͞Ε͔ͨΒͦͬͪ ʹૹ͓ͬͯ͘Α ͋Γ͕ͱ͏ʂ
  4. Webhookͷ৔߹ Mautic mymautic.com Your App yourapp.com ᶃYour AppͷΤϯυϙΠϯτʹWebhook ϖΠϩʔυΛૹ৴ POST

    https://yourapp.com/webhook {“contacts”: “ίϯλΫτ৘ใ”} {“success”: “true”} ίϯλΫτ৘ใ͕ߋ ৽͞Ε͔ͨΒͦͬͪ ʹૹ͓ͬͯ͘Α ͋Γ͕ͱ͏ʂ Web APIͷ৔߹ Mautic mymautic.com Your App yourapp.com ᶃMauticʹAPIϦΫΤετΛૹ৴ GET https://mymautic.com/api/contacts ᶄMautic͕ίϯλΫτ৘ใΛฦ٫ {“contacts”: “ίϯλΫτ৘ใ”} ͍͍Α ίϯλΫτ৘ ใͪΐ͏͍ͩ MauticͷWebhookΞΫγϣ ϯ͕ൃੜͨ͠λΠϛϯά ͰɺMautic͔ΒYour Appʹ HTTPϦΫΤετΛૹ৴͢Δ Your Appͷ೚ҙͷλΠϛϯ άͰɺYour App͔ΒMautic ʹHTTPϦΫΤετΛૹ৴͢ Δ
  5. MauticͰར༻ՄೳͳWebhookΞΫγϣϯ – ϝʔϧͷૹ৴/։෧ – ςΩετͷૹ৴ – ϑΥʔϜͷૹ৴ – ίϯλΫτͷ࡞੒/ߋ৽
 /ϙΠϯτͷมߋ/࡟আ

    – ϖʔδώοτ ࣍ͷΞΫγϣϯͷࡍʹɺMauticͰWebhookϖΠϩʔυΛૹ৴Ͱ͖Δ ͜ΕΒҎ֎ͷλΠϛϯάͰ WebhookΛىಈͰ͖Δͷ͔ʁ
  6. MauticͰར༻ՄೳͳWebhookΞΫγϣϯ – ϝʔϧͷૹ৴/։෧ – ςΩετͷૹ৴ – ϑΥʔϜͷૹ৴ – ίϯλΫτͷ࡞੒/ߋ৽
 /ϙΠϯτͷมߋ/࡟আ

    – ϖʔδώοτ ࣍ͷΞΫγϣϯͷࡍʹɺMauticͰWebhookϖΠϩʔυΛૹ৴Ͱ͖Δ Webhook͸Ωϟϯϖʔϯ ಺Ͱ΋ૹ৴Ͱ͖ΔͷͰɺ͜ ΕΒҎ֎ͷ೚ҙͷλΠϛϯ άͰτϦΨʔΛҾ͚Δ Yes! You can!
  7. WebhookΛ࡞੒͢Δ ʔ ࡞੒ը໘ Mautic mymautic.com Your App yourapp.com ໊લ ͳΜͰ΋OK

    ΢ΣϒϑοΫͷઆ໌ ͳΜͰ΋OK Secret ޙ΄Ͳղઆ ΢ΣϒϑοΫ POST URL ͜͜ʹMautic͔Βݺͼग़ ͯ͠΄͍͠URL(ԼهͰݴ͏ͱYour AppͷΤϯυϙ Πϯτ)Λઃఆ ΢ΣϒϑοΫΠϕϯτ ͜ͷwebhook಺Ͱར༻ͨ͠ ͍ΠϕϯτΛબ୒(ෳ਺બ୒Մ)
  8. WebhookΛςετ͢Δ – Zapier – https://zapier.com – Mautic ΠϯςάϨʔγϣϯ͕༻ҙ͞Ε͍ͯ·͢
 – RequestBin

    – https://requestbin.com/ – ZapierͷΑ͏ͳαʔϏεͰ͢
 – ngrokʢݺͼํɿΤϯάϩοΫʣ – localhostͰಈ͍͍ͯΔΞϓϦέʔγϣϯΛίϚϯυҰͭͰ֎෦ʹެ։ Ͱ͖ΔπʔϧͰ͢
  9. ૹͬͨΑ ߈ܸ evilmautic.com ͳͥγʔΫϨοτ͕ར༻͞ΕΔͷ͔ Mautic mymautic.com Your App yourapp.com POST

    https://yourapp.com/webhook {“contacts”: “ίϯλΫτ৘ใ”} {“success”: “true”} ҎԼͷਤ͸Webhookͷେ·͔ͳྲྀΕͰ͢ ߈ܸऀ ૹͬͨΑ ͋Γ͕ͱ͏ʂ ͋Γ͕ͱ͏ʂ POST https://yourapp.com/webhook {“contacts”: “ِ෺ίϯλΫτ৘ใ”} ߈ܸऀʹΑͬͯσʔλ͕
 վ͟ΜͰ͖ͯ͠·͏
  10. ૹͬͨΑ ߈ܸ evilmautic.com ͳͥγʔΫϨοτ͕ར༻͞ΕΔͷ͔ Mautic mymautic.com Your App yourapp.com POST

    https://yourapp.com/webhook
 Header: Webhook-Signature=XXX {“contacts”: “ίϯλΫτ৘ใ”} {“success”: “true”} γʔΫϨοτ͕͋Δͱɾɾɾ ߈ܸऀ ૹͬͨΑ ϋογϡ஋Λൺֱ͠ ͯɾɾɾҰகͨ͠ʂ ͋Γ͕ͱ͏ʂ POST https://yourapp.com/webhook {“contacts”: “ِ෺ίϯλΫτ৘ใ”} γʔΫϨοτʹΑͬͯ ૹ৴͞ΕͨWebhookϖΠϩʔυͷ ৴པੑΛূ໌Ͱ͖·͢ ϋογϡ஋Λൺֱ͠ ͯɾɾɾ
 Ұக͠ͳ͍ʂ ͜Ε͸ແࢹ͠Α͏
  11. # σΟϨΫτϦʹҠಈ $ cd /path/to/dir
 # ӈͷίʔυΛwebhookTest.phpͱͯ͠อଘ $ vi webhookTest.php

    αϯϓϧίʔυΛಈ͔ͦ͏ खॱ2. 
 αϯϓϧίʔυΛίϐʔͯ͠ɺϩʔΧϧ؀ڥʹϑΝΠϧ࡞ͬͯ഑ஔ
  12. αϯϓϧίʔυΛಈ͔ͦ͏ खॱ6. 
 ngrokͰϩʔΧϧαʔόʔΛ֎෦ެ։͠ɺੜ੒͞ΕͨURLΛίϐʔ͢Δ # ϩʔΧϧαʔόʔΛ֎෦ެ։͢Δ $ ngrok http 8888


    ngrok by @inconshreveable (Ctrl+C to quit) Session Status online Session Expires 1 hour, 59 minutes Version 2.3.40 Region United States (us) Web Interface http://127.0.0.1:4040 Forwarding http://49ab448ec357.ngrok.io -> http://localhost:8888 Forwarding https://49ab448ec357.ngrok.io -> http://localhost:8888 Connections ttl opn rt1 rt5 p50 p90 0 0 0.00 0.00 0.00 0.00
  13. WebhookΛςετ ʔ ਖ਼ৗܥ ςετϖΠϩʔυΛૹ৴ϘλϯΛԡͯ͠ɺ
 ͲΜͳϩά͕ग़ྗ͞ΕΔ͔֬ೝ͢Δ ← ΫϦοΫʂ ϩάϑΝΠϧΛ֬ೝ͢Δͱɺauthenticity verification OKͱදࣔ͞Ε͍ͯΔɻ

    → Mautic͔Βૹ৴͞ΕΔϦΫΤετʹ෇༩͞Ε͍ͯΔ Webhook-Signature ϔομͱɺwebhookTest.php ಺Ͱܭࢉ͞Εͨϋογϡ஋ΛরΒ͠߹Θͤͯ߹கͨ͠ɻ
  14. WebhookΛςετ ʔ ҟৗܥ ࣍͸ϦΫΤετʹ Webhook-Signature ϔομʔ͕෇༩͞Ε͍ͯͳ͍৔ ߹Λݕূɻ Postman౳ͰWebhookૹ৴ઌʹ
 POSTϦΫΤετΛૹ৴͢Δ ↓

    ΫϦοΫʂ ϩάϑΝΠϧΛ֬ೝ͢ΔͱɺWebhook not authentic! ͱදࣔ͞Ε͍ͯΔɻ → ϔομͷ஋Λ֬ೝ͢Δ͜ͱͰɺ҆શͳϦΫΤετͱͦ͏Ͱͳ͍΋ͷΛৼΓ෼͚Δ͜ͱ͕ Ͱ͖ͨɻ