\WP_Buoy_SMS_Email_Bridge

Class to schedule, poll, and forward messages over IMAP to an SMS.

Summary

Methods
Properties
Constants
register()
run()
scheduleNext()
unscheduleNext()
No public properties found
hook
backoff_multiplier
backoff_time_step
backoff_max_seconds
No protected methods found
No protected properties found
N/A
connectImap()
getNextRunTime()
forward()
No private properties found
N/A

Constants

hook

hook

The WordPress hook name ("tag").

backoff_multiplier

backoff_multiplier

The back-off timing multiplier.

backoff_time_step

backoff_time_step

The back-off time step in seconds.

backoff_max_seconds

backoff_max_seconds

The maximum number of seconds to backoff for.

Methods

register()

register() 

Registers bridge to WordPress API.

run()

run(integer  $post_id) 

Performs a runtime check of an email address for SMS messages.

This method is called by the WP-Cron system to perform a check of an given team's SMS/txt email account.

Parameters

integer $post_id

The ID of the post ("team") whose settings to use.

scheduleNext()

scheduleNext(integer  $post_id, integer  $backoff_step) 

Schedules the next run for the given team.

This method uses an adaptive recheck algorithm similar to TCP's adaptive retransmission timer.

Parameters

integer $post_id
integer $backoff_step

unscheduleNext()

unscheduleNext(integer  $post_id) 

Unschedules the next run of the bridge for the given team post.

Parameters

integer $post_id

connectImap()

connectImap(\WP_Post  $wp_post) : \Horde_Imap_Client_Socket

Connects to an IMAP server with the settings from a given post.

Parameters

\WP_Post $wp_post

Returns

\Horde_Imap_Client_Socket

getNextRunTime()

getNextRunTime(integer  $backoff_step) : integer

Determines when the next run should be.

This is implemented by providing a "back-off timer" value as a counter beginning from 0. When 0 is passed, the back-off value is equal to the time step. Otherwise, the counter is multiplied by a multiplier (usually 2).

This creates the following situation when the time step is 30 seconds and the multiplier value is 2:

Run number 1, back-off counter 0, next run in 30 seconds
Run number 2, back-off counter 1, next run in 1 minute
Run number 3, back-off counter 2, next run in 2 minutes
Run number 4, back-off counter 4, next run in 4 minutes
Run number 5, back-off counter 8, next run in 8 minutes

Total elapsed time for five runs is 15 minutes and 30 seconds. When message activity is detected, we reset the counter to 0.

This algorithm helps ensure we don't overload the remote server but still lets us detect the presence and then forward messages relatively quickly when an active conversation is taking place.

The algorithm above is similar to TCP's adaptive retransmission algorithm. (Research that algorithm for more insight on this.)

Parameters

integer $backoff_step

Returns

integer

forward()

forward(\WP_Buoy_SMS  $SMS, string  $text, array<mixed,\WP_Buoy_User>  $recipients, \WP_Buoy_User  $sender, array<mixed,string>  $headers = array()) 

Forwards a text message to a set of recipients.

Parameters

\WP_Buoy_SMS $SMS

The WP_Bouy_SMS object to use.

string $text
array<mixed,\WP_Buoy_User> $recipients
\WP_Buoy_User $sender
array<mixed,string> $headers

Extra headers to set.