I'm using the Twilio API to send SMS text messages to my app via HTTP POST coming into a REST site on my org. When the message comes in, a Message__c record is created and attached to a parent Conversation__c record with an OwnerId (a user). I need the user to get a push notification on Salesforce1 that a new message has arrived.
With Salesforce1, the only apparent way to trigger the notification is to post to chatter (either to a user's profile, or with a @mention). I finally figured out to set the Public Access Settings on the site to enable Chatter. So now, I can get a Chatter post to happen... but it doesn't trigger the notification. Not sure why?
I spent lots of time researching the PushNotification class, but that's for custom mobile apps -- doesn't work with Salesforce1.
I found that I had to use APEX/trigger rather than Process Builder to post to chatter -- Process Builder won't handle the chatter post from the Site Guest User, even if the Chatter is enabled for the guest user profile.
I've tried APEX for adding a feedItem -- very easy, and works, but no notification is triggered. Also tried ConnectApi:
ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), ParentId, ConnectApi.FeedElementType.FeedItem, Body);
Also works, but no notification. I tried setting the CreatedBy for the feedItem, but that's a System Field setting that the Guest User can't be assigned.
The notifications DO work if I trigger these methods from Exec Anon, because in those cases, the context user is me (with Sys Admin profile). So the code is "right", but the Site Guest User just can't quite do it.
Any ideas, hacks, workarounds?
I did see this old blog post for a workaround hack to let a person post to Chatter with an @mention to herself, that uses email to case to generate a Case, then sets Automated Case User to System, then uses that System user to post to Chatter, then a process builder to delete the case that was created. It's not really what I'm trying to accomplish, but the hack manages to engage a System User context. Could that work for my situation? This is for a managed package app, so I'm leary of creating Cases then deleting them.