Berkongsi
Webhooks adalah salah satu ciri yang paling berguna dalam platform kami. Ia membolehkan pemaju dan pemilik tapak mendengar acara dari peranti atau pelayan WhatsApp, yang berguna untuk membuat tugas automatik. Fungsi ini direka khusus untuk menerima acara sahaja, seperti khidmat pesanan ringkas (SMS), sembang WhatsApp, respons ussd dan pemberitahuan android.
Dihantar di: Feb 10, 2023 - 1,810 Pandangan
Gunakan Kes-kes
- Buat bot autoreply untuk SMS dan WhatsApp.
- Simpan mesej dan sembang ke pangkalan data anda sendiri semasa menerima.
- Simpan pemberitahuan ke pangkalan data anda sendiri semasa menerima.
- Simpan respons USSD pada pangkalan data anda sendiri semasa menerima.
- Hantar muatan ke alamat e-mel yang ditentukan.
- Hantar SMS/Chat apabila anda menerima pemberitahuan daripada Facebook.
- Lakukan sesuatu apabila anda menerima pemberitahuan daripada apl.
Bagaimana Ia Berfungsi
Sistem mendapat peristiwa yang diterima daripada kedua-dua sumber, maka url webhook akan digunakan dan data muatan dihantar. Apabila pelayan webhook anda menerimanya, anda boleh melakukan apa sahaja dengan muatan itu sendiri. Muatan dihantar dengan kaedah POST untuk memastikan penghantaran yang cekap.
Struktur Muatan
Struktur muatan adalah mudah; Anda hanya perlu menyemak jenis muatan dan kemudian memproses kandungan badan data.
# sms
[
"type" => "sms", // type of payload: received sms
"data" => [
"id" => 2, // unique id from the system
"rid" => 10593, // unique id from the device
"sim" => 1, // sim card slot
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"phone" => "+639760713666", // sender phone number
"message" => "Hello World!", // message
"timestamp" => 1645684231 // receive timestamp
]
]
[
"type" => "whatsapp", // type of payload: received whatsapp chat
"data" => [
"id" => 2, // unique id from the system
"wid" => "+639760713666", // whatsapp account phone number
"phone" => "+639760666713", // sender phone number
"message" => "Hello World!", // message
"timestamp" => 1645684231 // receive timestamp
]
]
# ussd
[
"type" => "ussd", // type of payload: received ussd response
"data" => [
"id" => 98, // unique id from the system
"sim" => 1, // sim card slot
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"code" => "*143#", // ussd code
"response" => "Sorry! You are not allowed to use this service.", // ussd response
"timestamp" => 1645684231 // receive timestamp
]
]
# Pemberitahuan
[
"type" => "notification", // type of payload: received notification
"data" => [
"id" => 77, // unique id from the system
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"package" => "com.facebook.katana", // application package name
"title" => "Someone commented on your post!", // notification title
"content" => "Someone commented on your post!", // notification content
"timestamp" => 1645684231 // receive timestamp
]
]
Contoh Kod
Webhooks)
/**
* Validate webhook secret
*/
if(isset($request["secret"]) && $request["secret"] == $secret):
// Valid webhook secret
$payloadType = $request["type"];
$payloadData = $request["data"];
// do something with the payload
print_r($payloadType);
print_r($payloadData);
else:
// Invalid webhook secret
endif;