Skip to content

Commit

Permalink
MMS - Add File/Image Attachment
Browse files Browse the repository at this point in the history
This is the beginning of being able to add a file or image attachment to a sms message when sending.

Issue #9
  • Loading branch information
jpwalters committed Apr 18, 2016
1 parent ff7c0e1 commit b429d0d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
9 changes: 9 additions & 0 deletions sms-conversations/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@
clear: both;
height: 0;
}

#media-url {
padding-left:5px;
cursor: pointer;
}

.fa-paperclip:hover {
cursor: hand;
}
32 changes: 30 additions & 2 deletions sms-conversations/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ $(document).ready(function(){

$('#sendSMS').click(function(e) {
e.preventDefault();

$.post(OpenVBX.home + "/messages/sms/" + $('#sms-messageid').val(),{to:$('#sms-to-phone').val(),from:$('#sms-from-phone').val(),content:$('#message-to-send').val()}, function( data ) {
$.post(OpenVBX.home + "/messages/sms/" + $('#sms-messageid').val(),{to:$('#sms-to-phone').val(),from:$('#sms-from-phone').val(),content:$('#message-to-send').val(),media_urls:$('#sms-media-url').val()}, function( data ) {

if(!data.error) {
$('#message-to-send').val('');
Expand All @@ -225,6 +224,35 @@ $(document).ready(function(){
setTimeout(function() { getSmsHistory($('#sms-to-phone').val()); }, 1500);
});

$("#media-url").click(function() {

document.getElementById("sms-media-url").click();

return false; // avoiding navigation
});

$('#sms-media-url').change(function(evt) {
var formData = new FormData(document.getElementById("sms-media-url"));
formData.append('action','mms-file-upload');

$.ajax({
url: 'sms-conversation',
type: 'POST',
async: true,
enctype: 'multipart/form-data',
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
data: formData,
error: function(){
console.log("error");
},
success: function(data){
console.log("PHP Output:");
console.log( data );
}
});
});

$('.quick-call-button').click(function(e) {
e.preventDefault();

Expand Down
Binary file added sms-conversations/mms-files/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions sms-conversations/sms-conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
$mediaObj = $ci->twilio->request($media_url, "GET");
echo $mediaObj->ResponseText;

exit;
}
else if($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['action'] === 'mms-file-upload') {
//var_dump($_FILES, $_POST);
echo '{"url":"http://test.com"}';

exit;
}

Expand Down Expand Up @@ -86,7 +92,9 @@

<div class="chat-message clearfix">
<textarea name="message-to-send" id="message-to-send" placeholder ="Type your message" rows="3"></textarea>
<i id="media-url" class="fa fa-paperclip fa-2x"></i>
<button id="sendSMS">Send</button>
<input type="file" id="sms-media-url" value="" style="display: none;">
<input type="hidden" id="sms-messageid" value="">
<input type="hidden" id="sms-to-phone" value="">
<input type="hidden" id="sms-from-phone" value="">
Expand Down

3 comments on commit b429d0d

@boblaw
Copy link

@boblaw boblaw commented on b429d0d Jun 2, 2016

Choose a reason for hiding this comment

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

JP,

Any success with the MMS image attachment working? Hangup?

@jpwalters
Copy link
Owner Author

Choose a reason for hiding this comment

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

JP ... Thanks for checking on this feature. The main hold up is getting OpenVBX to approve the changes in their project. In order to send attachments with a sms message OpenVBX needs to enhance a few areas. I've already written the code and opened a pull request. twilio/OpenVBX#366. Feel free to additionally add some chatter on that project to encourage them to merge those enhancements into their project so that I can release this feature in my plugin.

@oibikunle
Copy link

Choose a reason for hiding this comment

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

I was wondering if anyone can confirm if this code is ready as a plug in... I need to send MMS like right now... I am even ready to take a risk of using anything right now. Please help me!

Please sign in to comment.