CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviSMS »
  • Implementing a Contact.sms api action
Pages: [1]

Author Topic: Implementing a Contact.sms api action  (Read 3345 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Implementing a Contact.sms api action
October 25, 2012, 11:02:38 am
Hey there,

Following on from http://forum.civicrm.org/index.php/topic,26374.0.html I am starting to implement a Contact.sms api action*

* as opposed to Phone.sms or Sms.send - I am open to being persuaded on that.

Do people have any thoughts on the method that this should wrap around?

My initial thoughts are CRM_Activity_BAO_Activity::sendSMS or ::sendSMSMessage

PS my investigations into http://drupal.org/project/smsframework and http://drupal.org/project/voipdrupal didn't turn up much useful.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Implementing a Contact.sms api action
October 25, 2012, 11:07:34 am
PS you can follow progress here: https://github.com/michaelmcandrew/org.thirdsectordesign.chainsms and if someone wants to tell me why when I enable that extension the api does not get registered, I would be grateful.

Code: [Select]
ubuntu@scratch:/projects/sms$ drush civicrm-api contact.sms
Array
(
    [is_error] => 1
    [error_message] => API (contact,sms) does not exist (join the API team and implement it!)
)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Implementing a Contact.sms api action
October 25, 2012, 11:25:22 am
It took me a minute, but I'm persuaded that a 'contact.sendSms' would make some sense. (Note: I don't think 'sms' is a verb.)

There are a few different APIs one might implement, but I think they'd have different meanings:

 * Contact.sendSms -- Send a message to particular person -- automatically figure out how to route the message (eg figure out which phone number makes sense and then compose the message) and create an activity record.
 * Activity.create (type==SMS) -- Record the fact that an SMS was sent. This might be used when importing a database of past SMS interactions from a third-party application.
 * Sms.send / Sms.receive -- Low-level SMS API for processing messages. These APIs would work in terms of phone#s rather than contact ID#s. If a downstream developer has some special logic for picking phone#s or creating activities, then he would use this instead of Contact.sendSms.
« Last Edit: October 25, 2012, 11:28:33 am by totten »

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Implementing a Contact.sms api action
October 25, 2012, 12:28:18 pm
Thanks for your thoughts, Tim :)

Quote
I don't think 'sms' is a verb

I wonder if sms is a verb in the same way that email is a verb. The API construction is 'entity action', 'noun verb' makes the meaning clearer.

Quote
Sms.send / Sms.receive

Could potentially / alternatively be Phone.sendSms and Phone.receiveSms.  I am also 'dreaming' about Phone.Call :)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Implementing a Contact.sms api action
October 25, 2012, 12:34:09 pm
Re: my question about the extension api problem - Xavier thinks bug (
Quote
[7:10pm] xavier_: I think totten did mention the api wasn't part of the path if put in extension, but not sure if bug or fixed
[7:10pm] xavier_: I'd say bug, but didn't look at it
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Implementing a Contact.sms api action
October 25, 2012, 01:36:46 pm
Tim would know - but I thought this function was supposed to add your php dir to the path.

Code: [Select]
function _chainsms_civix_civicrm_config(&$config = NULL) {
  static $configured = FALSE;
  if ($configured) return;
  $configured = TRUE;

  $template =& CRM_Core_Smarty::singleton();

  $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  $extDir = $extRoot . 'templates';

  if ( is_array( $template->template_dir ) ) {
      array_unshift( $template->template_dir, $extDir );
  } else {
      $template->template_dir = array( $extDir, $template->template_dir );
  }

  $include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
  set_include_path( $include_path );
}


There was some conversation on the api list about it - Nicholas G was going to take a look.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Implementing a Contact.sms api action
October 25, 2012, 01:40:11 pm
Quote from: Michael McAndrew on October 25, 2012, 12:34:09 pm
Re: my question about the extension api problem - Xavier thinks bug (
Quote
[7:10pm] xavier_: I think totten did mention the api wasn't part of the path if put in extension, but not sure if bug or fixed
[7:10pm] xavier_: I'd say bug, but didn't look at it

If you're using civix, then the extension adds itself to the include_path using hook_civicrm_config, so you can call APIs that are provided by extensions.

There was a bug with the API's introspection -- eg when using the API explorer to list available API entities+actions, it would only display actions that were in the main 'modules/civicrm/api/v3' folder. A patch was committed (for 4.2 IIRC) that allowed introspection to work better with other code.

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Implementing a Contact.sms api action
October 29, 2012, 05:26:50 am
Quote
There was a bug with the API's introspection -- eg when using the API explorer to list available API entities+actions, it would only display actions that were in the main 'modules/civicrm/api/v3' folder. A patch was committed (for 4.2 IIRC) that allowed introspection to work better with other code.

OK - this was a capitalisation issue.  When generating api files, Civix should capitalise stuff - will submit issue on github.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Implementing a Contact.sms api action
October 29, 2012, 11:12:53 am
so https://github.com/michaelmcandrew/org.thirdsectordesign.chainsms now implements a new api action for Contacts contact.sms which takes a 'text' parameter which uses token subsitution. e.g.
Code: [Select]
$results=civicrm_api("Contact","sms", array (version => '3', 'id' =>'1', 'text' =>'{contact.first_name} is a {contact.job_title} at {contact.current_employer}'));
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Implementing a Contact.sms api action
March 18, 2013, 06:53:09 am
Hi michael,

could you push the api in the core?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviSMS »
  • Implementing a Contact.sms api action

This forum was archived on 2017-11-26.