Firebase allows you to quickly develop and deploy high-quality apps, paired with extended functionalities that enable you to continuously optimize and scale your app. Firebase also hosts pre-packaged, open-source extensions to help you automate common development tasks.
Today, we are excited to discuss the MessageBird | Firebase extension.
The MessageBird extension on Firebase connects you to the world’s largest omnichannel portfolio to deliver messages and notifications on all of your customers’ preferred channels. Powered by MessageBird’s global connectivity, this means you can reach your customers quickly — and anywhere in the world!
To further streamline the process, when you add a document to a specific Firebase collection, the extension will utilize MessageBird’s Conversations API to convert that document into readable text and update the document with the delivery status.
In this article, you will learn how you can get sending in just a few steps!
When I heard that my colleagues worked on creating a Firebase extension that would allow you to easily integrate message sending in your app, I had to take it for a spin and build something with it.
Note: You can find the MessageBird extension on Firebase here.
To bring the extension into context, we will consider a small example app for managing a queue at a restaurant.
The restaurant owner or host can register customers on the web UI or the customers can register themselves. When their table is ready, with just a click of a button from a restaurant employee, a notification will be sent to the customer to return to the restaurant.
While there are many ways to build a system for notifying users, the best solutions alleviate as much work as possible for the customers. This helps businesses provide their customers an excellent experience.
That is why we will utilize the new MessageBird | Firebase extension to ensure customers are notified through an SMS. This way, customers can enjoy their waiting time and not stress about missing out, while also making it easier for restaurant staff to manage the queue.
While this example sends a SMS notification, within the extension you can use whichever channel your customer prefers (WhatsApp, Google’s Business Messages, Facebook Messenger, Telegram, Line, Viber, etc.) so you can adapt the notification to the customer's preferences.
In this example, we will assume you have a Firebase and MessageBird account.
If you don't have a MessageBird account, you can create one here.
To begin, it requires information from your MessageBird account.
First, you will need your API key to allow the Firebase extension to interact with the MessageBird API on your behalf. You can find the API key here. Second, you will need an SMS number and an installed SMS channel. If you do not have a Channel ID already, navigate here to get one.
Once you have both your API key and an SMS Channel ID, return to your Firebase console and navigate to the Extensions tab.
From here, install the [Send Messages with Messagebird] Firebase extension.
During the install wizard, you will be prompted to add your API key and a collection name to use.
The collection name will be listened to by the Firebase extension.
When a document is added to the collection, it will trigger the extension.
Under the hood, the extension is a Cloud Function, which listens to changes on the specified collection, reads the added document and interacts with the MessageBird API to send the message.
Once your extension installation is complete, navigate to Firestore within the Firebase console. Then, add a collection ID that matches the collection name you used when installing the extension.
Note: It is very important to restrict who can write and read to this collection. If the collection is left open, third parties may be able to read the numbers of users and even send messages with your account. We would recommend using the Firestore security rules so only specific users have these privileges and follow all the security best practices put forth by the Firebase team.
The messages collection that we configured during setup will store all your messages. To send an SMS message, you will need to add a document to the collection you named in the wizard using this format:
Using the example from above, we add this document to the “messages” collection. When this new document shows up in Firestore, the extension will automatically trigger and send a message built from the document’s fields.
You can subscribe to these updates via the Firestore snapshots and inform the owner of the status of the message — for example, if someone puts the incorrect number into the form and the message fails to be delivered.
Once the document is added to the collection, the MessageBird extension will then interact with the MessageBird API and update the document with extra fields as below. The delivery.state field below depicts the different statuses the message can be in.
If sending a message results in a failure, the state field will be ERROR, and the error field will be populated with an error message string.
It is also possible to observe errors from the extension and usage via in the Cloud functions tab in the Firebase console:
Now, you no longer require a direct backend API integration to interact with the MessageBird API.
You can streamline the implementation via the Firebase extension and make sending notifications as simple as document write operations — no matter the communication channel you want to use.
This is only scratching the surface of what you can do with the extension and our API.
We offer many channels and we also have an incredibly powerful visual editor in Flow Builder that allows you to create even more dynamic experiences.
Following the use case above, Flow Builder would allow you to add a reply feature to the notifications sent, which enables the customer to reply with a keyword or phrase to cancel their reservation. But that’s for a future article! 🙂
If you have any other use cases that you would be interested in, our solution engineers are here to help you. Please contact our team here and let us know!