How to add variables and tokens

Variables used in the messages can be chosen to whatever you like. It's best to make them self-explicatory of course. In custom code you will get the value from the node, user, comment, heartbeat activity, ... object.

With rules and heartbeat_rules we may need a custom token. Underneath is an example on how to create your own avatar token and album pictures. The example beneath has a situation of an image that has a node_reference field to either album or user album. Ofcourse, you could adjust this whatever you want.

Code: 
<?php
/**
 * Implementation of hook_token_list().
 */

function heartbeat_example_token_list($type = 'all') {

  $tokens = array();
  if ($type == 'heartbeat_message') {

    // Define a custom avatar
    $tokens['heartbeat_message']['avatar'] = t("The avatar of the user");

  }
  elseif ($type == 'node') {

    // Define images for albums
    $tokens['node']['type-image-url'] = t("The url of the image content type image");
    $tokens['node']['type-image-link'] = t("The image of the image content type with a link to it");
    $tokens['node']['type-album-url'] = t("The url of the album content type");
    $tokens['node']['type-album-link'] = t("The image of the album content type with a link to it");  
    $tokens['node']['type-image-album-link'] = t("A link to the album of the uploaded image");
  }
  return $tokens;
}
?>
<?php
/**
* Implementation of hook_token_values().
*/

function heartbeatrules_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {

    case 'heartbeat_message':
      $account = user_load($object->uid);
      $values['avatar'] = '<span class="my-clss">' . l(theme('imagecache', 'avatar_45x45', $account->picture), 'user/' . $account->uid, array('html' => TRUE)) . '</span>';        
     
    break;

    case 'node':
    if($object->type == 'image') {
      // image are shown with a known preset : avatar_60x60
      if(!empty($object->images['thumbnail'])) {
        $values['type-image-url'] =  url($object->images['thumbnail']);
        $thumb = theme('imagecache', 'avatar_60x60', $object->images['thumbnail'], $object->title, $object->title);
        $values['type-image-link'] = l($thumb,'node/'.$object->nid, array('html' => TRUE), array('attributes'=> array('class'=>'beat-content')));
        if(!empty($object->field_albumref[0]['nid'])) {
            $album_nid = $object->field_albumref[0]['nid'];
            $album_link = $object->field_albumref[0]['view'];          
        }
        else if(!empty($object->field_useralbumref[0]['nid'])) {
            $album_nid = $object->field_useralbumref[0]['nid'];
            $album_link = $object->field_useralbumref[0]['view'];  
        }
        $values['type-image-album-link'] = $album_link;
      }
      else {
        $values['type-image-link'] = $values['type-image-url'] = $values['type-image-album-link'] ='';
      }
    }
    else if ($object->type == 'album') {
    if(isset($object->field_image[0]['filepath'])) {
        $values['type-album-url'] =  url($object->field_image[0]['filepath']);
        $thumb = theme('imagecache', 'avatar_60x60', $object->field_image[0]['filepath'], $object->title, $object->title);
        $values['type-album-link'] = l($thumb,'node/'.$object->nid, array('html' => TRUE), array('attributes'=> array('class'=>'beat-content')));    
      }
      else {
        $values['type-album-link'] = $values['type-album-url'] = '';
      }
    }
    break;
  }
  return $values;
}
?>