For additional handling of sending messages, the framework should be extended with additional hook-ops.
Some reasons for that were:
* sms validation (check length of message, valid recipients,...)
* Flexible gateway selection per user/scope ( a site could change the gateway due to receiving country)
* Flexible gateway options per user (site could give user opportunity to use its own account)
* SMS limit per user/node/time/group/role/...
* message conversion ( e.g. adding flexible links)
* logging/storage of sent messages
* increase/decrease userpoints (when messaging will be part of a premium account, left messages could be decreased)
In my to come implementation for smscreator there are a lot of modules integrated that need pre and post processing. So for providing this gateway for sms framework, and the other parts independently on the gateway, we should add such additional hooks to the framework.
This would ease integration of additional gateway-independent message handling.
So sms_send() could look like this
*retrieve default gateway
*call hook_send_sms:PRE PROCESS
**params by ref: $number, $message, $options, $gateway
**return: ERROR messages (on error skip message sending)
*call hook_send_sms:PROCESS
**params by ref: $number, $message, $options, $gateway
**return: <none>
*call GATEWAY SEND function
*call hook_send_sms:POST PROCESS
*call ERROR handling
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | sms.module.patch | 642 bytes | sepla |
| #9 | smsframework-442748.patch | 8.42 KB | derhasi |
| #8 | smsframework-442748-2.patch | 5.98 KB | derhasi |
| #7 | smsframework-442748-1.patch | 5.34 KB | derhasi |
| #7 | sms_legacy.module.txt | 1016 bytes | derhasi |
Comments
Comment #1
Will White commentedHi Derhasi,
Thanks for the request. Looks like what you need could probably with drupal_alter().
Something like:
We would just have to come up with a standard way to store the "message" in a structured array. This would probably work:
Comment #2
derhasi commentedI agree, using a general $message object would be the best method, so any module can add its own necessary information. Besides I also suggest a $gateway object, that will contain the $gateway->type and additional options, like ->uri / ->user / -> password.
So $message could contain
If this approach should be realized, we should think about legacy to existing sms.module implementations.
Comment #3
derhasi commentedIs 2.x-dev the place for adding this functionality?
Comment #4
derhasi commentedI would start tonight with writing some changes to 2.x-dev implementing send:pre process/process/past process
My suggestion for the hook-ops would be:
pre send process
- collect all information for $message (except gateway dependent)
- validate message in basic
send process
- will be performed before the original _send-function of the given gateway
- will only change $message->gateway - information
- will validate only gateway-dependent cases (like, user may not send via gateway A, but may send via gateway B)
post send process
- will handle suffescully sent or failed messages
- may save a message to database
- may fire status messages
- may create new content (like nodes)
- ...
My suggestion for a minimum $message-object would be:
$message ->
type (string)
- type definition (e.g. by module) - like "sms_blast", "node_link", ...
mid (int)
- serial for outgoing AND incoming messages
direction (string)
- either 'out'(sending) or 'in'(receiving)
recipient (integer?)
- the international number for messages (without +, without whitespaces)
sender (integer?)
- the international number of the sender
message (string)
- the to send message
gateway (object)
- the gateway object should at least contain the 'type' attribute
Should be introduced a new hook for legacy reasons?
(1) hook_sms($op,$message)
(2) hook_sms_alter($message,$op)
(3a) hook_sms_incoming($op,$message)
(3b) hook_sms_outgoing($op,$message)
I would favourize (1), so we could secure only
gatewaymay be edited (and maybe recipient & sender).Comment #5
Will White commentedHi derhasi,
Sorry for the delay on this. This looks good. Yes these changes should go into 2.x. Will these changes alter the parameters in sms_send() at all. I think we should avoid that if possible because there would be quite a bit of legacy code to update.
We should remove the word 'process' from each of the $ops and instead just have 'pre send', 'send', and 'post send'.
How will we determine $message->type?
Thanks for your work on this!
Comment #6
derhasi commentedI would propose that any module that uses sms.module to send an sms has to define
->typeitself, likenode_save(), that has to have a$node->typedefined.For legacy I would add the opportunity to internally keep opportunity (1)
sms_send($number,$message,$options=array())but define it as (2)sms_send($message,$a1 = NULL, $a2 = NULL)and switch to (1) if $a1 is given as a string. $message->type then would be set to 'legacy'.hook_sms($op, $message)
OPs:
may call hook_sms_send via sms_legacy_sms("send",$message) in a sms_legacy.module
after that op the gateway_send will be called
may call hook_sms_incoming("pre process") via sms_legacy_sms("pre receive,$message) in a sms_legacy.module
may call hook_sms_incoming("process") via sms_legacy_sms("receive,$message) in a sms_legacy.module
may call hook_sms_incoming("post process") via sms_legacy_sms("post receive,$message) in a sms_legacy.module
There could be a sms_gateway.module, that will add the default gateway in sms:pre send, if there's none given. But for the first steps, I try to use the given gateway handling.
If you have any suggestions, you can contact me via IRC ;)
Comment #7
derhasi commentedbuilt a first patch on sms.module and sms_legacy.module
Comment #8
derhasi commentedChanged
$message- object to$sms-object to avoid legacy confusion.Also changed sms_send_log() to fit in new gateway_send.
Comment #9
derhasi commentedChanged some minor errors (e.g. an error logs were sent falsely).
Applied the patch on the current dev.
Comment #10
derhasi commentedComment #11
derhasi commentedrecognized a bug in the patch, please replace
$sms->text = $a2;with$sms->text = $a1;insms_send().I will include it in a patch file soon, after I've discussed with Will about further steps.
Comment #12
eric_a commentedmessaging_message_send($destinations, &$message, $method, $queue = 0) invokes hooks like the ones mentioned above:
'prepare/message_alter', 'render', 'presend', 'queue', 'afterqueue', 'multisend', 'aftersend'.
Perhaps leveraging the Messaging API is a good idea, i.e. declare a dependency on Messaging.
Comment #13
derhasi commentedYes, implementing messaging as dependency might be a solution. Personally I have to take a closer look on that module.
Comment #14
eric_a commentedderhasi, looking at the existing bridge messaging_sms.module first might be helpfull. And perhaps a straight dependency on this one rather than on messaging.module?
EDIT:
In which case the hooks that are currently not declared with a callback would have to be added to the callback list in messaging_sms_messaging(), most notably 'prepare callback', 'presend callback', 'aftersend callback'.
SMS Framework would focus on implementations of these hooks. In order to get the hooks invoked all sending would be done through the messaging API: either messaging_message_send($destinations, &$message, $method, $queue = 0) or messaging_message_send_user($account, &$message, $method = NULL, $queue = 0).
Comment #15
derhasi commentedIntegration to messaging would be a more generic way, I guess. But I hadn't had enough time to have a closer look on it :(
Comment #16
sepla commentedSubscribed.
Comment #17
sepla commentedI were in the process of developing a new module which was eager to jump in while processing outgoing messages. We decided to not to apply derhasi's patch and waiting for the new stable API to come. So I did a quick dirty hack to let every module that implements
hook_send_sms_alter()in at the end of the process. So we could keep the work on, thanks for the great job.Comment #18
almaudoh commentedThe ideas in this thread would be good to explore further for D8.
Comment #19
dpiI think D8 is in a good position for hooks. #2716479: Clean up and document sms_send hooks will trim some of the remaining fat for send operations.
Comment #20
almaudoh commentedWe are not likely to change hooks in 7.x-1.x and there is no plan for a 7.x-2.x branch.