Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

SMS/MMS Display Attached Media #342 #343

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions OpenVBX/controllers/messages/inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function scripts($group = false)
'original_called' => $item->called,
'original_caller' => $item->caller,
'owner_type' => $item->owner_type,
'sid' => $item->call_sid,
);

}
Expand Down Expand Up @@ -310,6 +311,7 @@ private function inbox($group = false)
'original_called' => $item->called,
'original_caller' => $item->caller,
'owner_type' => $item->owner_type,
'sid' => $item->call_sid,
);

}
Expand Down
37 changes: 37 additions & 0 deletions OpenVBX/views/messages/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,43 @@
<h3>Transcription</h3>
<?php endif; ?>
<div class="message-transcript"><?php echo (is_null($message->content_text) ? "(no transcription)" : $message->content_text) ?></div>
<?php if(substr($message->call_sid,0,2) == 'MM'):
echo "<br><br><h3>Media Attachements</h3>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't control spacing with <br>. This is what css is for.


$ci = & get_instance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost all controller logic. Move the logic to controllers/messages/details.php and include a 'media' member in the $details array. Default it to an empty array.

Then here you can check if (count($media)) to add the appropriate output.


require_once(APPPATH . 'libraries/twilio.php');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library is old and deprecated. It should not be used. Instead use the newer Services/Twilio php library. As mentioned above this code should be moved to the controller and the media information added to the $details array. Add something like this between lines 354 & 356 in controllers/messages/details.php:

if (substr($message->callused, 0, 2) == 'MM') {
    $account = OpenVBX::getAccount();
    $message = $account->messages->get($message->call_sid);

    foreach ($message->media as $mediaItem) {
        $details['media'][] = array(
            'sid' => $mediaItem->sid, 
            'content_type' => $mediaItem->content_type, 
            'uri' => $mediaItem->uri,
        );
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let me know if the Twilio library gives you any crap here. The included library is a bit out of date and may be missing some fixes. If it is out of date either you can update it in your branch or I can update it in this repo and you can pull from upstream to get the changes.


$ci->twilio = new TwilioRestClient($ci->twilio_sid,$ci->twilio_token,$ci->twilio_endpoint);

$media_url = "Accounts/{$this->twilio_sid}/Messages/{$message->call_sid}/Media.xml";

$mediaObj = $ci->twilio->request($media_url, "GET");

$media_xml = $mediaObj->ResponseXml;

foreach($media_xml->MediaList->Media as $media):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit pick: we can use the alternate syntax control when breaking from HTML, but once within PHP we should always use braces around control structures.


$media_uri = 'https://api.twilio.com/2010-04-01/Accounts/'.$this->twilio_sid.'/Messages/'.$message->call_sid.'/Media/'.$media->Sid;

if(strpos($media->ContentType,'image')!==false):
echo '<img src="'.$media_uri.'" type="'.$media->ContentType.'">';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image elements don't have a type attribute. We should parse out the content type to build the appropriate url. This is something that can be done in the controller to keep all logic away from the view.

elseif(strpos($media->ContentType,'audio')!==false):
echo '<audio controls>';
echo '<source src="'.$media_uri.'" type="'.$media->ContentType.'">';
echo 'Your browser does not support the audio element.</audio>';
elseif(strpos($media->ContentType,'video')!==false):
echo '<video controls>';
echo '<source src="'.$media_uri.'" type="'.$media->ContentType.'">';
echo 'Your browser does not support the video element.</video>';
endif;

echo '<br>'.$media->ContentType.': <a href="'.$media_uri.'">Click To Download</a>';
echo '<br><br>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with <br>.


endforeach;

endif; ?>
</div><!-- .message-details-transcript -->

</div><!-- .vbx-content-container -->
Expand Down
3 changes: 2 additions & 1 deletion OpenVBX/views/messages/inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@
<input type="checkbox" name="message[id][]" value="<?php echo $item['id'] ?>" />
</div>
</td>
<td class="message-caller message-details-link">
<td class="message-caller message-details-link" style="width:220px">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it is ok to let this column's size vary based on its content.

<span class="phone-number"><?php echo $item['caller'] ?></span>
<a href="<?php echo site_url("messages/details/{$item['id']}")?>" class="quick-call-button"><span class="replace"><?php echo $item['caller'] ?></span></a>
<?php if($item['type'] == 'sms'): ?>
<a href="<?php echo site_url("messages/details/{$item['id']}")?>" class="quick-sms-button"><span class="replace"><?php echo $item['caller'] ?></span></a>
<?php echo (substr($item['sid'],0,2) == 'MM'?'<span class="phone-number" title="Click to View Media">&nbsp;mms</span>':'') ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure about this. There's probably a more attractive way of doing this without having to create an icon for all the default themes.

<?php endif; ?>

<div id="quick-call-popup-<?php echo $item['id'] ?>" class="quick-call-popup hide">
Expand Down