Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
brienne
Developer Documentation
Commits
a2566e43
Commit
a2566e43
authored
8 years ago
by
Effy Elden
Browse files
Options
Downloads
Patches
Plain Diff
CRM-20238 - Add documentation for hook_civicrm_inboundSMS
parent
43532d62
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/hooks/hook_civicrm_inboundSMS.md
+96
-0
96 additions, 0 deletions
docs/hooks/hook_civicrm_inboundSMS.md
mkdocs.yml
+2
-0
2 additions, 0 deletions
mkdocs.yml
with
98 additions
and
0 deletions
docs/hooks/hook_civicrm_inboundSMS.md
0 → 100644
+
96
−
0
View file @
a2566e43
# hook_civicrm_inboundSMS
## Description
This hook is called when an inbound SMS has been received, processed by the
provider extension, but not matched or processed by CiviSMS.
## Definition
```
hook_civicrm_inboundSMS(&$from, &$fromContactID = NULL, &$to, &$toContactID = NULL, &$body, &$trackID)
```
## Parameters
*
string
`$from`
- the phone number the message is from, as set by SMS provider
*
int
`$fromContactID`
- can be set to override default matching
*
string
`$to`
- the optional phone number the message is to, as set by SMS provider
*
int
`$toContactID`
- can be set to override default matching
*
string
`$body`
- the body text of the message
*
string
`$trackID`
- The tracking ID of the message
## Added
4.
7
## Notes
Using this hook you can
## Examples
Alter the incoming SMS From number to match how phone numbers are stored in the database
```
php
<?php
function
myextension_civicrm_inboundSMS
(
&
$from
,
&
$fromContactID
=
NULL
,
&
$to
,
&
$toContactID
=
NULL
,
&
$body
,
&
$trackID
)
{
// Alter the sender phone number to match the format used in database
$from
=
str_replace
(
'+614'
,
'04'
,
$from
);
}
```
Automatically add contacts to a group if the message contains 'SUBSCRIBE'
```
php
<?php
function
myextension_civicrm_inboundSMS
(
&
$from
,
&
$fromContactID
=
NULL
,
&
$to
,
&
$toContactID
=
NULL
,
&
$body
,
&
$trackID
)
{
// Add contact to group if message contains keyword
if
(
stripos
(
$body
,
'SUBSCRIBE'
)
!==
false
)
{
$escapedFrom
=
CRM_Utils_Type
::
escape
(
$from
,
'String'
);
$fromContactID
=
CRM_Core_DAO
::
singleValueQuery
(
'SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%'
.
$escapedFrom
.
'"'
);
if
(
$fromContactID
)
{
CRM_Contact_BAO_GroupContact
::
AddContactsToGroup
(
array
(
$fromContactID
),
5
,
'SMS'
,
'Added'
);
}
}
}
```
Send an automatic response to incoming messages
```
php
<?php
function
myextension_civicrm_inboundSMS
(
&
$from
,
&
$fromContactID
=
NULL
,
&
$to
,
&
$toContactID
=
NULL
,
&
$body
,
&
$trackID
)
{
// Send an automatic response
$provider
=
CRM_SMS_Provider
::
singleton
(
array
(
'provider_id'
=>
1
));
$provider
->
send
(
$from
,
array
(
'To'
=>
$from
),
'Thank you for your message'
,
NULL
,
NULL
);
}
```
Implement custom logic to match the message to the sender
```
php
<?php
function
myextension_civicrm_inboundSMS
(
&
$from
,
&
$fromContactID
=
NULL
,
&
$to
,
&
$toContactID
=
NULL
,
&
$body
,
&
$trackID
)
{
// Implement custom matching logic
// If there are multiple contacts with the phone number, preference the one that has been sent an SMS most recently
$fromContactID
=
CRM_Core_DAO
::
singleValueQuery
(
"
SELECT civicrm_contact.id FROM civicrm_phone
JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id
LEFT JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = civicrm_contact.id
AND civicrm_activity_contact.record_type_id = 3
LEFT JOIN civicrm_activity ON civicrm_activity.id = civicrm_activity_contact.activity_id
AND civicrm_activity.activity_type_id = 4
WHERE !civicrm_contact.is_deleted
AND phone LIKE
\"
%"
.
$escapedFrom
.
"
\"
ORDER BY civicrm_activity.activity_date_time DESC"
);
}
```
This diff is collapsed.
Click to expand it.
mkdocs.yml
+
2
−
0
View file @
a2566e43
...
...
@@ -153,6 +153,8 @@ pages:
-
hook_civicrm_viewProfile
:
hooks/hook_civicrm_viewProfile.md
-
Report hooks
:
-
hook_civicrm_alterReportVar
:
hooks/hook_civicrm_alterReportVar.md
-
SMS hooks
:
-
hook_civicrm_inboundSMS
:
hooks/hook_civicrm_inboundSMS.md
-
Uncategorized hooks
:
-
hook_civicrm_alterBadge
:
hooks/hook_civicrm_alterBadge.md
-
hook_civicrm_alterBarcode
:
hooks/hook_civicrm_alterBarcode.md
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment