Details
-
Type:
New Feature
-
Status: Done/Fixed
-
Priority:
Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.7.16
-
Fix Version/s: 4.7.21
-
Component/s: None
-
Labels:
-
Versioning Impact:Minor (add functionality in backwards-compatible manner)
-
Documentation Required?:Developer Doc
-
Funding Source:Needs Funding
-
Verified?:No
Description
It would be beneficial to have a callable hook when an inbound SMS is received.
Potential use cases include:
- Applying custom logic to match the From phone number to contacts
- Reformatting the From phone number to match the structure in the database (for example, replacing +614 with 04 for Australian mobile numbers)
- Taking actions based on incoming SMS (such as adding the contact to a group if the message includes a specific keyword)
- Sending an automatic reply SMS back to the sender
Hi Effy Elden,
This seems useful for the first use case you provided. I've actually implemented most of the other three use cases using existing hooks. Since inbound SMS creates an activity, I've had good success with hook_civicrm_pre and hook_civicrm_post to implement what you're describing. I don't know if that influences your hook design at all.
For instance, this is the code at the heart of an extension I wrote. This is an "SMS forwarder" - when someone with an open CiviCase sends an inbound SMS, automatically send an outgoing SMS to their case manager(s) to copy what they said: