/plushcap/analysis/vonage/vonage-building-text-message-group-chat-nexmo-sms-api-php-dr

Building Text Message Group Chat with the Nexmo SMS API and PHP

What's this blog post about?

To exercise the new PHP client library a bit, we're going to build a simple SMS group chat where a user's inbound message is sent to all the other members of the chat. This script accepts [inbound webhooks](https://docs.nexmo.com/messaging/setup-callbacks#setting) from Nexmo, and processes the message. The logic here is simple, if the user is subscribed and active, their message should be sent to all the _other_ members. We need to check that the user is able to post a message to the group. If we found a user in the database, it means they were at some time subscribed to the group, but we need to check if they've left. The script uses regular expressions and `switch` statements to handle different commands and messages. It also logs important events such as users joining or leaving a group, sending a message, or replying to a user's message. Once all the message are sent, it adds the new message to the log collection on the database. With that we've setup a simple script that accepts inbound messages, replies to some of them, and relays others to a group. The command concept could be extended to more complex and interactive auto-responder bots, or this could be repurposed as a SMS distribution list that allows anyone to send an inbound message to a group of people.

Company
Vonage

Date published
May 13, 2021

Author(s)
Tim Lytle

Word count
1815

Language
English

Hacker News points
None found.


By Matt Makai. 2021-2024.