Monthly Archives: February 2016

Formidable integration with intercom.io

Intercom is a CRM platform that acts as the single channel between client and service provider. The tool can be used to manage, communicate and tag users in addition to a variety of other features.

My requirement was to tag intercom users once a formidable entry is marked as approved. The idea is to identify the logged in WP user and tag the corresponding user entry in intercom. Key pieces to the integration are given below:
1) A view with single field edit links.
2) Once the the entry is updated, based on certain conditions, send data to intercom and tag users.
3) Intercom API documentation can be found here.
4) Intercom’s PHP library and installation instructions are in Github here.

Code snippet
require_once 'intercom/vendor/autoload.php';
use Intercom\IntercomBasicAuthClient;
add_action('frm_after_update_field', 'frm_trigger_entry_update'); //action triggered during entry update from view
function frm_trigger_entry_update($atts){
$entry = FrmEntry::getOne($atts['entry_id']);
do_action('frm_after_update_entry', $entry->id, $entry->form_id); //callback to FP frm_after_update_entry hook
}
add_action('frm_after_update_entry', 'send_to_intercom', 10, 2); //action triggered after update entry
function send_to_intercom($entry_id, $form_id){
$intercom = IntercomBasicAuthClient::factory(array( //intercom initialization
'app_id' => 'app_id',
'api_key' => 'app_key'
));
global $wpdb,$frm_entry,$frm_entry_meta;
//replace 28, 342, 285, 341 with your form and field ids respectively
if($form_id == 28 && FrmEntryMeta::get_entry_meta_by_field($entry_id, 342) == 'Approved') {
$tag_user = new WP_User( FrmEntryMeta::get_entry_meta_by_field($entry_id, 285) );
$intercom->tagUsers(array( //call to 'tagUsers' intercom api function
"name" => FrmEntryMeta::get_entry_meta_by_field($entry_id, 341).": Approved",
"users" => array(
array("email" => $tag_user->user_email)
)
));
}
}
}

Hope this helps! Please feel free to share your experiences and let me know if there are better ways to use the intercom API.