English Addendum
5. How to Implement a New Driver (Example: Mailgun)
This guide walks you through the process of adding a new third-party service to the MMS. We will use the Mailgun API as a concrete example for sending emails. Prerequisites:- You have a Mailgun account with an active domain and an API key.
- You have installed the official Laravel HTTP client (
guzzlehttp/guzzle).
Step 1: Create the Driver Class First, create a new file for your driver. Since Mailgun is for email, we’ll place it in the
Email drivers directory.
File: app/Services/Mms/Drivers/Email/MailgunApiDriver.php
The class must implement the SenderInterface and should extend AbstractSender to leverage the built-in logging helper.
Step 2: Add Configuration to
config/mms.php
Now, register your new driver within the email channel in your config/mms.php file.
Step 3: Update Environment Variables (
.env)
Add the necessary credentials for your new driver to your .env file.
Step 4: Test Your New Driver You can now test your new driver immediately using the
test:mms command.
- Run the command:
- Check the logs:
Examine the
notification_dispatch_logscollection. You should find a new document for this test.
- The
statusshould besent. - The
gateway_message_idshould contain the ID returned by Mailgun. - The
gateway_responsefield will have the full JSON response from the Mailgun API for debugging.
Tambahan Dokumentasi Bahasa Indonesia
5. Cara Mengimplementasikan Driver Baru (Contoh: Mailgun)
Panduan ini akan memandu Anda melalui proses penambahan layanan pihak ketiga baru ke dalam MMS. Kita akan menggunakan API Mailgun sebagai contoh konkret untuk mengirim email. Prasyarat:- Anda memiliki akun Mailgun dengan domain aktif dan sebuah API key.
- Anda telah menginstal HTTP client resmi Laravel (
guzzlehttp/guzzle).
Langkah 1: Buat Kelas Driver Pertama, buat file baru untuk driver Anda. Karena Mailgun adalah untuk email, kita akan menempatkannya di direktori driver
Email.
File: app/Services/Mms/Drivers/Email/MailgunApiDriver.php
Kelas ini harus mengimplementasikan SenderInterface dan sebaiknya extends AbstractSender untuk memanfaatkan helper logging bawaan.
Langkah 2: Tambahkan Konfigurasi ke
config/mms.php
Sekarang, daftarkan driver baru Anda di dalam channel email pada file config/mms.php Anda.
Langkah 3: Perbarui Variabel Environment (
.env)
Tambahkan kredensial yang diperlukan untuk driver baru Anda ke file .env.
Langkah 4: Uji Driver Baru Anda Anda sekarang dapat menguji driver baru Anda secara langsung menggunakan command
test:mms.
- Jalankan command:
- Periksa log:
Periksa koleksi
notification_dispatch_logs. Anda seharusnya menemukan dokumen baru untuk pengujian ini.
statusseharusnyasent.gateway_message_idseharusnya berisi ID yang dikembalikan oleh Mailgun.- Field
gateway_responseakan berisi respons JSON lengkap dari API Mailgun untuk keperluan debugging.
