/**
  * Implements TelegramInterface::getContactByName()
  */
 function getContactByName($name)
 {
     $peer = TelegramContact::nameToPeer($name);
     $contacts = $this->getStorage()->contactLoadMultiple(array('peer' => $peer));
     return reset($contacts);
 }
 /**
  * Get peer's history
  *
  * @param string $peer
  *   Peer name or contact name with spaces replaced by '_'
  * @param int $limit
  *   Maximum number of messages, defaults to 40
  *
  * @return array
  *   Array of message objects
  */
 public function getHistory($peer, $limit = 40)
 {
     if ($this->execCommand('history', $peer, $limit)) {
         $pattern = array(0 => '/(\\d+)\\s\\[(.*.)\\]\\s+(.*.)\\s(«««|»»»|<<<|>>>)(.*)/u');
         $mapping = array(0 => 'string', 1 => 'idmsg', 2 => 'date', 3 => 'name', 4 => '_direction', 5 => 'text');
         $translator = function ($data) {
             if ($data['_direction'] == '«««' || $data['_direction'] == '<<<') {
                 $data['direction'] = 'incoming';
             } else {
                 $data['direction'] = 'outgoing';
             }
             $data['peer'] = TelegramContact::nameToPeer($data['name']);
             return new TelegramMessage($data);
         };
         return $this->parseResponse($pattern, $mapping, 'idmsg', $translator);
     }
 }