function feedhistory($connection = 'default', $limit)
{
    $annotations = Annotation::on($connection)->with('Attachments')->where('id', '<', $limit)->orderBy('id', 'desc')->take(20)->get();
    Carbon::setToStringFormat(DateTime::ISO8601);
    $result = [];
    foreach ($annotations as $annotation) {
        $result[] = json_decode($annotation->toJson());
    }
    return json_encode($result);
}
 $nick = $elem_search->user->screen_name;
 $profile_image_url = $elem_search->user->profile_image_url;
 $testo_tweet = $elem_search->text;
 if (isset($elem_search->retweeted_status)) {
     $testo_tweet = 'RT: ' . $elem_search->retweeted_status->text;
 }
 if (isset($elem_search->coordinates)) {
     $point = \GeoJson\GeoJson::jsonUnserialize($elem_search->coordinates);
 }
 // Entites https://dev.twitter.com/overview/api/entities
 $hashtags = [];
 foreach ($elem_search->entities->hashtags as $ht) {
     // lo # non c'e' se serve va messo
     $hashtags[] = $ht->text;
 }
 $ann = Annotation::on($connection_name)->where('sourceId', $id_tweet)->get();
 if ($ann->count() == 0) {
     $annotation = new Annotation(array('author' => $nick, 'source' => Source::TWITTER, 'sourceId' => $id_tweet, 'text' => $testo_tweet, 'textHtml' => parseTweet($testo_tweet), 'hashtags' => $hashtags));
     $annotation->setConnection($connection_name);
     $annotation->save();
     $result = Parser::parse($testo_tweet);
     if ($result != false) {
         $evaluation = new Evaluation(array('annotation_id' => $annotation->id, 'sessione' => $result->sessione, 'evento' => $result->evento, 'punteggio' => $result->punteggio));
         $evaluation->setConnection($connection_name);
         $evaluation->save();
     }
     $imageCount = 0;
     if (isset($elem_search->entities->media)) {
         foreach ($elem_search->entities->media as $media) {
             $imageCount++;
             $resources[] = $media->media_url;
    foreach ($res as $sms) {
        //    [sms_id] => 2
        //    [author] => +393395039915
        //    [plainText] => 0054006500640074
        $sms_id = $sms->sms_id;
        $lastId = $sms_id;
        $author = $sms->author;
        $plainText = $sms->plainText;
        preg_match_all('/#(\\w+)/', $plainText, $matches);
        $hashtags = array();
        if (isset($matches) && count($matches) > 0) {
            foreach ($matches[1] as $val) {
                $hashtags[] = $val;
            }
        }
        $ann = Annotation::on($connection_name)->where('sourceId', $sms_id)->get();
        if ($ann->count() == 0) {
            $annotation = new Annotation(array('author' => $author, 'source' => Source::SMS, 'sourceId' => $sms_id, 'text' => $plainText, 'textHtml' => $plainText, 'hashtags' => $hashtags));
            $annotation->setConnection($connection_name);
            $annotation->save();
            $result = Parser::parse($plainText);
            if ($result != false) {
                $evaluation = new Evaluation(array('annotation_id' => $annotation->id, 'sessione' => $result->sessione, 'evento' => $result->evento, 'punteggio' => $result->punteggio));
                $evaluation->setConnection($connection_name);
                $evaluation->save();
            }
        }
    }
    $filesystem->put('last.sms', $lastId);
} catch (\Exception $e) {
    $log->addError($e->getFile() . ' on ' . $e->getLine() . ' ' . ' because : ' . $e->getMessage());
 foreach ($obj_telegram->result as $message_telegram) {
     $message = $message_telegram->message;
     $idMessaggio = $message->message_id;
     if ($idMessaggio <= $reqN) {
         continue;
     }
     $reqN = $idMessaggio;
     $nomeMittente = $message->from->first_name;
     $cognomeMittente = $message->from->last_name;
     if (isset($message->from->username)) {
         $userName = $message->from->username;
     } else {
         $userName = '';
     }
     $author = $cognomeMittente . ' ' . $nomeMittente . ' @' . $userName;
     $ann = Annotation::on($connection_name)->where('sourceId', $idMessaggio)->get();
     if ($ann->count() == 0) {
         //TESTO
         if (isset($message->text)) {
             $testo = $message->text;
             if ($testo == '/start') {
                 continue;
             }
             $annotation = new Annotation(array('author' => $author, 'source' => Source::TELEGRAM, 'sourceId' => $idMessaggio, 'text' => $testo, 'textHtml' => $testo, 'hashtags' => array()));
             $annotation->setConnection($connection_name);
             $annotation->save();
             //primo carattere @IndabaBot
             if (strpos($testo, '@IndabaBot') === false) {
                 $result = Parser::parse($testo);
             } else {
                 $testoDaParsare = mb_substr($testo, 11, strlen($testo) - 11, 'utf-8');