Skip to main content

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.
  1. Run the command:
  1. Check the logs: Examine the notification_dispatch_logs collection. You should find a new document for this test.
  • The status should be sent.
  • The gateway_message_id should contain the ID returned by Mailgun.
  • The gateway_response field will have the full JSON response from the Mailgun API for debugging.
You have successfully integrated a new third-party service into the MMS. This process can be repeated for any API, making the system incredibly flexible and future-proof.

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.
  1. Jalankan command:
  1. Periksa log: Periksa koleksi notification_dispatch_logs. Anda seharusnya menemukan dokumen baru untuk pengujian ini.
  • status seharusnya sent.
  • gateway_message_id seharusnya berisi ID yang dikembalikan oleh Mailgun.
  • Field gateway_response akan berisi respons JSON lengkap dari API Mailgun untuk keperluan debugging.
Anda telah berhasil mengintegrasikan layanan pihak ketiga baru ke dalam MMS. Proses ini dapat diulangi untuk API apa pun, membuat sistem ini sangat fleksibel dan siap untuk masa depan.