Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Added web support for attachments
Jake Daynesb35f60d72786
diff --git a/web/components/MessageThread.vue b/web/components/MessageThread.vueindex 0f0f222b..e2ed4739 100644--- a/web/components/MessageThread.vue+++ b/web/components/MessageThread.vue@@ -95,8 +95,13 @@<v-list-item-title>{{ thread.contact | phoneNumber }}</v-list-item-title>- <v-list-item-subtitle>- {{ thread.last_message_content }}+ <v-list-item-subtitle class="text--secondary">+ <span v-if="thread.last_message_content">+ {{ thread.last_message_content }}+ </span>+ <span v-else>+ <v-icon small>{{ mdiPaperclip }}</v-icon> Multimedia Message+ </span></v-list-item-subtitle></v-list-item-content><v-list-item-action>@@ -150,6 +155,7 @@ import {mdiCheck,mdiAlert,mdiAccount,+ mdiPaperclip,} from '@mdi/js'@Component@@ -160,6 +166,7 @@ export default class MessageThread extends Vue {mdiAlert = mdiAlertmdiCheck = mdiCheckmdiCheckAll = mdiCheckAll+ mdiPaperclip = mdiPaperclipget threads(): Array<MessageThread> {return this.$store.getters.getThreadsdiff --git a/web/models/message.ts b/web/models/message.tsindex 35306648..c0d09f12 100644--- a/web/models/message.ts+++ b/web/models/message.ts@@ -1,6 +1,12 @@+export interface MessageAttachment {+ content_type: string+ url: string+}+export interface Message {contact: stringcontent: string+ attachments?: MessageAttachment[]created_at: stringfailure_reason: stringid: stringdiff --git a/web/pages/messages/index.vue b/web/pages/messages/index.vueindex a1a2a154..78a46533 100644--- a/web/pages/messages/index.vue+++ b/web/pages/messages/index.vue@@ -33,6 +33,16 @@placeholder="Enter your message here"label="Content"></v-textarea>+ <v-textarea+ v-model="formAttachments"+ :error="errors.has('attachments')"+ :error-messages="errors.get('attachments')"+ :disabled="sending"+ outlined+ rows="2"+ placeholder="https://example.com/image.jpg, https://example.com/video.mp4"+ label="Attachment URLs (comma separated, optional)"+ ></v-textarea><v-btntype="submit"class="primary"@@ -72,6 +82,7 @@ export default {sending: false,formPhoneNumber: '',formContent: '',+ formAttachments: '',errors: new Map(),}},@@ -85,11 +96,31 @@ export default {sendMessage() {this.errors = new Map()this.sending = true++ const attachments = []+ if (this.formAttachments.trim() !== '') {+ const urls = this.formAttachments.split(',')+ for (const u of urls) {+ const cleanUrl = u.trim()+ if (!cleanUrl) continue++ let contentType = 'application/octet-stream'+ const lowerUrl = cleanUrl.toLowerCase()+ if (lowerUrl.endsWith('.jpg') || lowerUrl.endsWith('.jpeg')) contentType = 'image/jpeg'+ else if (lowerUrl.endsWith('.png')) contentType = 'image/png'+ else if (lowerUrl.endsWith('.gif')) contentType = 'image/gif'+ else if (lowerUrl.endsWith('.mp4')) contentType = 'video/mp4'++ attachments.push({ content_type: contentType, url: cleanUrl })+ }+ }+axios.post('/v1/messages/send', {to: this.formPhoneNumber,from: this.$store.getters.getOwner,content: this.formContent,+ attachments: attachments,sim: this.simSelected.code,}).then(() => {@@ -113,6 +144,9 @@ export default {),)}+ if (response.data.data.attachments) {+ errors.set('attachments', response.data.data.attachments)+ }if (response.data.data.from) {this.$store.dispatch('addNotification', {message: response.data.data.from[0],