English Version
This document provides a step-by-step guide on how to configure each communication channel and its specific gateways within the Multi-Messaging System (MMS).1. Common Channel Setup Concepts
Before configuring a specific gateway, it’s important to understand what each channel type generally requires:- Email: You need credentials for an email sending service. This can be a traditional SMTP server or a modern API-based provider like Mailtrap, Mailgun, or SendGrid. You will always need an API key/secret and usually a “from” address.
- WhatsApp: This channel requires a connection to a WhatsApp Gateway API. These are services that bridge your application with the WhatsApp Business Platform. You will need the gateway’s URL and authentication credentials (like an API key or session token).
- Telegram: This requires you to create a “Bot” via Telegram’s BotFather. The setup will provide you with a unique Bot Token. You will also need the recipient’s
Chat ID. - FCM (Firebase Cloud Messaging): This requires a Firebase project. The primary credential is a JSON file (
firebase_credentials.json) containing your project’s service account keys, which allows your server to send push notifications securely. - Internal (Database): This channel is built-in and requires no external setup. It relies on your existing
Usermodel and Laravel’s notification system to store messages in thenotificationsdatabase collection.
2. Specific Gateway Setup Instructions
A. Email: Mailtrap API
This driver sends emails synchronously via the Mailtrap Sending API, providing immediate feedback.- Prerequisites: An active Mailtrap account with a verified sending domain.
- Step 1: Get Credentials
- Log in to your Mailtrap account.
- Navigate to “Sending Domains” and select your domain.
- Under the “API & Integrations” tab, you will find your API Token.
- Step 2: Update
.envFile
- Step 3: Verify
config/mms.phpEnsure the driver is configured correctly. Theclassandconfigkeys should match the following:
B. WhatsApp: WAHA (WhatsApp HTTP API)
This driver connects to a WAHA server instance, which can be self-hosted or provided by a third party.- Prerequisites: A running and accessible WAHA server instance.
- Step 1: Get Credentials
- You need the URL of your WAHA server (e.g.,
http://localhost:3000). - You need the Session Name you are using in WAHA (e.g.,
default). - If your WAHA instance is secured, you will need the API Token (sometimes referred to as
X-Api-Key).
- Step 2: Update
.envFile
- Step 3: Verify
config/mms.php
C. Telegram Bot
This driver uses your own Telegram Bot to send messages.- Prerequisites: A Telegram account.
- Step 1: Create a Bot and Get Token
- In Telegram, search for the user
BotFatherand start a chat. - Send the command
/newbot. - Follow the prompts to name your bot and choose a username.
- BotFather will provide you with a unique Bot Token.
- Step 2: Get a Recipient Chat ID
- Find your newly created bot in Telegram and send it a message.
- Open your browser and navigate to the following URL, replacing
YOUR_BOT_TOKENwith your actual token:https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates - Look for the JSON response. Inside
result[0].message.chat, you will find theid. This is your Chat ID.
- Step 3: Update
.envFile Thelaravel-notification-channels/telegrampackage reads its token fromconfig/services.php, so we add it there.
- Step 4: Update
config/services.php
- Step 5: Verify
config/mms.phpThe Telegram driver in MMS doesn’t need specific config, as it relies on the global service configuration.
3. Advanced: Customizing Internal Database Notifications
The internal database channel is powerful because you can store complex, structured data directly in the notification, thanks to MongoDB’s schema-less nature. This allows you to differentiate notification types without creating new notification classes. Use Case: You want to send notifications for different business entities, like aContract or an Invoice, and have the frontend display them differently.
Step 1: Prepare the Data in the Job
In the job that sends the internal notification (e.g., SendInternalNotification), construct a detailed payload. The key is to add a structured entity object.
File: app/Jobs/SendInternalNotification.php
GenericDatabaseNotification class takes whatever array it’s given and saves it. When you send a notification for a contract, the data field in your notifications MongoDB collection will look like this:
Versi Bahasa Indonesia
Dokumen ini menyediakan panduan langkah-demi-langkah untuk mengonfigurasi setiap channel komunikasi dan gateway spesifiknya di dalam Multi-Messaging System (MMS).1. Konsep Umum Konfigurasi Channel
Sebelum mengonfigurasi gateway tertentu, penting untuk memahami apa yang umumnya dibutuhkan oleh setiap jenis channel:- Email: Anda memerlukan kredensial untuk layanan pengiriman email. Ini bisa berupa server SMTP tradisional atau penyedia berbasis API modern seperti Mailtrap, Mailgun, atau SendGrid. Anda akan selalu membutuhkan API key/secret dan biasanya alamat “from”.
- WhatsApp: Channel ini memerlukan koneksi ke API Gateway WhatsApp. Ini adalah layanan yang menjembatani aplikasi Anda dengan WhatsApp Business Platform. Anda akan memerlukan URL gateway dan kredensial otentikasi (seperti API key atau token sesi).
- Telegram: Ini mengharuskan Anda membuat “Bot” melalui BotFather milik Telegram. Pengaturan ini akan memberi Anda Token Bot yang unik. Anda juga akan memerlukan
Chat IDpenerima. - FCM (Firebase Cloud Messaging): Ini memerlukan proyek Firebase. Kredensial utamanya adalah file JSON (
firebase_credentials.json) yang berisi kunci akun layanan proyek Anda, yang memungkinkan server Anda mengirim notifikasi push dengan aman. - Internal (Database): Channel ini sudah terpasang dan tidak memerlukan pengaturan eksternal. Channel ini bergantung pada model
Useryang ada dan sistem notifikasi Laravel untuk menyimpan pesan di koleksi databasenotifications.
2. Instruksi Pengaturan Gateway Spesifik
A. Email: Mailtrap API
Driver ini mengirim email secara sinkron melalui Mailtrap Sending API, memberikan umpan balik langsung.- Prasyarat: Akun Mailtrap aktif dengan domain pengiriman yang terverifikasi.
- Langkah 1: Dapatkan Kredensial
- Login ke akun Mailtrap Anda.
- Navigasi ke “Sending Domains” dan pilih domain Anda.
- Di bawah tab “API & Integrations”, Anda akan menemukan API Token Anda.
- Langkah 2: Perbarui File
.env
- Langkah 3: Verifikasi
config/mms.phpPastikan driver dikonfigurasi dengan benar. Keyclassdanconfigharus sesuai dengan berikut ini:
B. WhatsApp: WAHA (WhatsApp HTTP API)
Driver ini terhubung ke instance server WAHA, yang bisa di-hosting sendiri atau disediakan oleh pihak ketiga.- Prasyarat: Instance server WAHA yang sedang berjalan dan dapat diakses.
- Langkah 1: Dapatkan Kredensial
- Anda memerlukan URL dari server WAHA Anda (misalnya,
http://localhost:3000). - Anda memerlukan Nama Sesi (Session Name) yang Anda gunakan di WAHA (misalnya,
default). - Jika instance WAHA Anda diamankan, Anda akan memerlukan API Token (terkadang disebut sebagai
X-Api-Key).
- Langkah 2: Perbarui File
.env
- Langkah 3: Verifikasi
config/mms.php
C. Telegram Bot
Driver ini menggunakan Bot Telegram Anda sendiri untuk mengirim pesan.- Prasyarat: Akun Telegram.
- Langkah 1: Buat Bot dan Dapatkan Token
- Di Telegram, cari pengguna
BotFatherdan mulai obrolan. - Kirim perintah
/newbot. - Ikuti petunjuk untuk memberi nama bot Anda dan memilih username.
- BotFather akan memberi Anda Token Bot yang unik.
- Langkah 2: Dapatkan Chat ID Penerima
- Temukan bot yang baru saja Anda buat di Telegram dan kirimkan pesan.
- Buka browser Anda dan navigasikan ke URL berikut, ganti
YOUR_BOT_TOKENdengan token Anda:https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates - Cari respons JSON. Di dalam
result[0].message.chat, Anda akan menemukanid. Ini adalah Chat ID Anda.
- Langkah 3: Perbarui File
.envPaketlaravel-notification-channels/telegrammembaca tokennya dariconfig/services.php, jadi kita menambahkannya di sana.
- Langkah 4: Perbarui
config/services.php
- Langkah 5: Verifikasi
config/mms.phpDriver Telegram di MMS tidak memerlukan konfigurasi khusus, karena ia bergantung pada konfigurasi layanan global.
3. Tingkat Lanjut: Kustomisasi Notifikasi Database Internal
Channel database internal sangat kuat karena Anda dapat menyimpan data terstruktur yang kompleks langsung di dalam notifikasi, berkat sifat schema-less dari MongoDB. Ini memungkinkan Anda untuk membedakan jenis notifikasi tanpa membuat kelas notifikasi baru. Studi Kasus: Anda ingin mengirim notifikasi untuk entitas bisnis yang berbeda, sepertiKontrak atau Faktur, dan ingin frontend menampilkannya secara berbeda.
Langkah 1: Siapkan Data di dalam Job
Di dalam job yang mengirimkan notifikasi internal (misalnya, SendInternalNotification), buat payload yang terperinci. Kuncinya adalah menambahkan objek entity yang terstruktur.
File: app/Jobs/SendInternalNotification.php
GenericDatabaseNotification akan mengambil array apa pun yang diberikan dan menyimpannya. Saat Anda mengirim notifikasi untuk sebuah kontrak, field data di koleksi notifications MongoDB Anda akan terlihat seperti ini:
