News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Moding SMF 2.1.3 forum to support SMS notifications

Started by Jdo300, March 18, 2023, 11:52:06 PM

Previous topic - Next topic

Jdo300

Hello,

I am one of the administrators of an SMF 2.1.3 forum that was just newly created and I'm wondering what it would take to integrate SMS notifications into my forum? I understand that it currently has the ability to provide email notifications out of the box, so one idea I had was to have users provide their cell number and current carrier when they register so that when the email notification system sends out notifications, it could use their phone number, mapped to the carrier-specific email gateway for their phone number, and send the SMS messages that way.

The problem is that though I have a programming background (Primarily C/C++ and C#), my expertise is not web programming (I've worked with basic HTML, CSS, and JavaScript but not PHP). Is this something even worth tackling or is there a better way to approach this all together?

Thank you,
Jason O

vbgamer45

Email sms gateways are hit or miss while free no guarantees it would be delivered.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Jdo300

Quote from: vbgamer45 on March 19, 2023, 12:51:45 AMEmail sms gateways are hit or miss while free no guarantees it would be delivered.

Thank you for your feedback. This is understandable. My major concern though is knowing how to actually implement this idea in the forum software. Here is my overall idea:

1. When a new user registers, they also include their cell number and carrier as inputs.

2. When they register, their phone number and carrier are used to map to the appropriate SMS email gateway address (if available) which is then stored in the database along with their other user info.

3. When the forum sends out a notification to their email, it also sends it out to their sms email address also.

Would anyone be willing to give me some pointers on where to start with this (I'm not familiar with the forum software structure) or is this a terrible idea? If so, is there a better approach?

Thanks!
Jason O

DeadMan...

Could they just use their carrier email to text address for their email address?

The main issue I'd have with notifications to SMS would be the fact that the notification email usually is pretty big, including having more information in them than most people would want coming to SMS. Some people still have costs with SMS, and a forum notification would more likely count as more than one SMS message.
I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

It is fundamentally a bad approach to use the email gateways to SMS. They don't work very well at the very best of times and some carriers block them.

The only *real* way to do it is to hook up something like Twilio but then you have to pay for every SMS you send.

Jdo300

Thank you for the feedback. The main reason we were exploring this approach was as an alternative to what we ultimately want, which is to have push notifications that can be sent from the forum directly to our app. The problem is that we don't currently have a login system implemented in the app itself to differentiate users so the notifications can go to the right place. Since the forum emails can target specific users, the thought was to piggyback off of this existing system and use SMS messages as the alternative way to achieve the goal.

Another idea we had was to somehow leverage the forum's ability to send browser push notifications to intercept them from the app (which displays the forum in an embedded browser window), and forward that to the phone as a popup. The challenge here is that it appears that iOS does not support browser push notifications.

One more idea we came up with is to see if there are any web services that could communicate with the forum via the SMF API to receive notifications and forward them. But I'm having trouble finding something that would work. Has anyone here ever attempted anything like this before? I'm trying to find the simplest/best approach to essentially provide push notifications to my app's users from the forum.

Arantor

Quote from: Jdo300 on March 21, 2023, 02:23:07 PMThe challenge here is that it appears that iOS does not support browser push notifications.

This is a feature coming in iOS 16.4.

Jdo300

Quote from: Arantor on March 21, 2023, 02:56:47 PM
Quote from: Jdo300 on March 21, 2023, 02:23:07 PMThe challenge here is that it appears that iOS does not support browser push notifications.

This is a feature coming in iOS 16.4.


That's good to know. Now, as for implementing it on the forum side. Do you know if there are any existing services that could connect to the forum through the API, a mod or some other mechanism to get the notifications or would this require a custom solution? I'm just trying to find a good, best direction for the next steps.

Arantor

The API didn't work properly in all cases for 2.0, I don't even think it's been updated for 2.1 (and the alerts system is new to 2.1)

But in all honesty you'd need custom code even with the API so it's not like you've actually lost out any there.

Jdo300

Quote from: Arantor on March 21, 2023, 05:20:56 PMThe API didn't work properly in all cases for 2.0, I don't even think it's been updated for 2.1 (and the alerts system is new to 2.1)

But in all honesty you'd need custom code even with the API so it's not like you've actually lost out any there.

I see. Well for someone who is new to modifying the forum software, what resources would you recommend I consult to learn what I need to know to do something like this? I currently have an account with OneSignal, which I can use to send out the notifications the forum generates. I'm not sure how to get started in this case. What would you suggest?

Arantor

I'm still not even sure I understand what you're trying to achieve - all I understand are the various ways you're trying to achieve users being told something somehow, so I'm not going to advise too deeply on how you should do it...

Jdo300

Quote from: Arantor on March 21, 2023, 09:54:06 PMI'm still not even sure I understand what you're trying to achieve - all I understand are the various ways you're trying to achieve users being told something somehow, so I'm not going to advise too deeply on how you should do it...

Sorry for the confusion. To make it all clear here's what I'm trying to accomplish.

I currently have an app that uses an embedded SMF Forum as the communications platform for its users. Meaning you can open the app on your phone, and one section of it takes you to a screen with an embedded browser that displays the associated SMF forum as part of the app.

When users get a notification for a post, etc., I want the app to receive a push notification, so they know about the new post or announcement, etc.

Jdo300

Today, I was reading a bit in the SMF documentation about integration hooks along with how to make a program that can send notifications directly to the Apple push Notification (APN) or Google Cloud Notification (GCN) services. I was looking at this page here, talking about integration hooks:

https://wiki.simplemachines.org/smf/Integration_hooks

I'm not familiar with PHP but I have some experience working with Node.js. Is it possible to have the integration hooks call a function in a Node.js script that could, for example, take some input notification information forwarded from the forum and execute code to send the info off to the APN or GCN services to get to my app?

Arantor

Integration hooks are simply points in the code where SMF asks 'hey, I'm here, any of you want to do anything' - so you can have integration hooks do anything. So they could certainly make a cURL call to a Node.js script somewhere. Or they could just call APNS and GCN directly if you have the device information to hand to do so.

Jdo300

Quote from: Arantor on March 22, 2023, 05:30:05 PMIntegration hooks are simply points in the code where SMF asks 'hey, I'm here, any of you want to do anything' - so you can have integration hooks do anything. So they could certainly make a cURL call to a Node.js script somewhere. Or they could just call APNS and GCN directly if you have the device information to hand to do so.

I see, thank you very much for the feedback. I realize that I will need to store the app tokens for each user on the forum so that it can supply this info to APN/GCN to forward to the correct devices. As far as standard practice goes, which table in the SMF database would be most appropriate to store such user information in? (or would it be best to create a separate data table that maps app tokens to the forum user IDs?).

Also are there any specific hooks that are called when the forum is sending out notifications? This is the code I would specifically need to hook into to forward the information to the push notification services.


Kindred

Do note the notifications are queued above only sent during periods of forum activity
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Quote from: Kindred on March 24, 2023, 02:44:58 PMDo note the notifications are queued above only sent during periods of forum activity

Ideally you'd run cron.php off a real cron once a minute to not have this problem.

Sesquipedalian

Quote from: Jdo300 on March 24, 2023, 01:53:41 PMAs far as standard practice goes, which table in the SMF database would be most appropriate to store such user information in? (or would it be best to create a separate data table that maps app tokens to the forum user IDs?).

The simplest approach would be to add custom columns to the members table.

QuoteAlso are there any specific hooks that are called when the forum is sending out notifications? This is the code I would specifically need to hook into to forward the information to the push notification services.

I was a little surprised to discover this, but no, there are no hooks called when sending notifications. There probably should be, and you can try requesting them to be added in a future release. I'm no longer on the official dev team, but back when I was I would have been fine with adding new hooks even in a patch release. If @shawnb61 has a similar view, you probably won't need to wait a terribly long time for those to be added—probably not in 2.1.4, but perhaps 2.1.5.

In the meantime, you'll probably need to make file edits. I personally suggest that you make those edits by inserting your own call_integration_hook() calls into the existing files, and then building the rest of your mod to integrate with them. Not only will this reduce the amount of changes you need to make to the existing files, but you could even submit those new hooks in a pull request on GitHub for possible inclusion in 2.1.5.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Jdo300

Quote from: Sesquipedalian on March 24, 2023, 07:55:18 PM
Quote from: Jdo300 on March 24, 2023, 01:53:41 PMAs far as standard practice goes, which table in the SMF database would be most appropriate to store such user information in? (or would it be best to create a separate data table that maps app tokens to the forum user IDs?).

The simplest approach would be to add custom columns to the members table.

QuoteAlso are there any specific hooks that are called when the forum is sending out notifications? This is the code I would specifically need to hook into to forward the information to the push notification services.

I was a little surprised to discover this, but no, there are no hooks called when sending notifications. There probably should be, and you can try requesting them to be added in a future release. I'm no longer on the official dev team, but back when I was I would have been fine with adding new hooks even in a patch release. If @shawnb61 has a similar view, you probably won't need to wait a terribly long time for those to be added—probably not in 2.1.4, but perhaps 2.1.5.

In the meantime, you'll probably need to make file edits. I personally suggest that you make those edits by inserting your own call_integration_hook() calls into the existing files, and then building the rest of your mod to integrate with them. Not only will this reduce the amount of changes you need to make to the existing files, but you could even submit those new hooks in a pull request on GitHub for possible inclusion in 2.1.5.

Thank you for providing that wealth of information. How would one get started in this regard? Which file(s) should I review to understand how the push notification system works in the SMF software? Also, some others mentioned cron jobs and things to execute the notifications etc. I'm just trying to find the best way to get up to speed with the architecture of the notification system so I can make the needed modifications effectively.

From a high level, how should I go about intercepting the notifications and where should I start?

Sesquipedalian

You will want to look at the ./Sources/tasks/*-Notify.php files. Those contain the code that send out the various notifications. You'll want to insert your custom hooks in those. The exact position where you should insert the custom code will vary from file to file, but in general you will probably want your hooks to be called at the end of the execution run.

You shouldn't need to worry too much about how the code in the *-Notify.php files gets called. You just need to add your custom code there so that when the task runs, your code is called too.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: