Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Add phone number selector

Acho Arnold9bd55983de76
diff --git a/web/components/FirebaseAuth.vue b/web/components/FirebaseAuth.vue
index 818dc74c..97306724 100644
--- a/web/components/FirebaseAuth.vue
+++ b/web/components/FirebaseAuth.vue
@@ -65,7 +65,7 @@ export default class FirebaseAuth extends Vue {
},
},
// Will use popup for IDP Providers sign-in flow instead of the default, redirect.
- signInFlow: this.$vuetify.breakpoint.mdAndDown ? 'redirect' : 'popup',
+ signInFlow: 'popup',
signInSuccessUrl: window.location.href,
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
diff --git a/web/components/MessageThread.vue b/web/components/MessageThread.vue
index 1108c21f..af250e6e 100644
--- a/web/components/MessageThread.vue
+++ b/web/components/MessageThread.vue
@@ -1,37 +1,77 @@
<template>
- <v-list two-line class="px-0 py-0" subheader>
+ <div>
<v-progress-linear
v-if="$store.getters.getLoadingThreads"
color="primary"
indeterminate
></v-progress-linear>
- <v-list-item-group>
- <template v-for="thread in threads">
- <v-list-item
- :key="thread.id"
- :to="'/threads/' + thread.id"
- class="py-1"
- >
- <v-list-item-avatar :color="thread.color">
- <v-icon dark> mdi-account </v-icon>
- </v-list-item-avatar>
- <v-list-item-content>
- <v-list-item-title>
- {{ thread.contact | phoneNumber }}
- </v-list-item-title>
- <v-list-item-subtitle>
- {{ thread.last_message_content }}
- </v-list-item-subtitle>
- </v-list-item-content>
- <v-list-item-action>
- <v-list-item-action-text>
- {{ threadDate(thread.order_timestamp) }}
- </v-list-item-action-text>
- </v-list-item-action>
- </v-list-item>
- </template>
- </v-list-item-group>
- </v-list>
+ <v-sheet
+ v-if="!$store.getters.getLoadingThreads && threads.length === 0"
+ class="text-center mt-8 mx-3"
+ :color="$vuetify.breakpoint.mdAndDown ? '#121212' : '#363636'"
+ >
+ <div v-if="$vuetify.breakpoint.mdAndDown">
+ <v-img
+ class="mx-auto mb-4"
+ max-width="80%"
+ contain
+ :src="require('assets/img/person-texting.svg')"
+ ></v-img>
+ <p v-if="$store.getters.getOwner" class="text--secondary">
+ Start sending messages
+ </p>
+ </div>
+ <v-btn
+ v-if="$store.getters.getOwner"
+ class="primary"
+ :to="{ name: 'messages' }"
+ >
+ <v-icon>mdi-plus</v-icon>
+ New Message
+ </v-btn>
+ </v-sheet>
+ <div v-if="$store.getters.getPhones.length === 0" class="px-4 text-center">
+ <p>
+ Install the mobile app on your android phone to start sending messages
+ </p>
+ <v-btn class="primary" :href="$store.getters.getAppData.appDownloadUrl">
+ <v-icon>mdi-download</v-icon>
+ Install App
+ </v-btn>
+ </div>
+ <v-list two-line class="px-0 py-0" subheader>
+ <v-list-item-group>
+ <template v-for="thread in threads">
+ <v-list-item
+ :key="thread.id"
+ :to="'/threads/' + thread.id"
+ class="py-1"
+ :class="{
+ 'px-6': $vuetify.breakpoint.mdAndDown,
+ 'px-3': $vuetify.breakpoint.lgAndUp,
+ }"
+ >
+ <v-list-item-avatar :color="thread.color">
+ <v-icon dark> mdi-account </v-icon>
+ </v-list-item-avatar>
+ <v-list-item-content>
+ <v-list-item-title>
+ {{ thread.contact | phoneNumber }}
+ </v-list-item-title>
+ <v-list-item-subtitle>
+ {{ thread.last_message_content }}
+ </v-list-item-subtitle>
+ </v-list-item-content>
+ <v-list-item-action>
+ <v-list-item-action-text>
+ {{ threadDate(thread.order_timestamp) }}
+ </v-list-item-action-text>
+ </v-list-item-action>
+ </v-list-item>
+ </template>
+ </v-list-item-group>
+ </v-list>
+ </div>
</template>
<script lang="ts">
diff --git a/web/components/MessageThreadHeader.vue b/web/components/MessageThreadHeader.vue
index 0eb2b368..c27366b2 100644
--- a/web/components/MessageThreadHeader.vue
+++ b/web/components/MessageThreadHeader.vue
@@ -2,14 +2,17 @@
<v-sheet
class="pa-4 d-flex"
:elevation="$vuetify.breakpoint.lgAndUp ? 0 : 2"
- :color="$vuetify.breakpoint.lgAndUp ? 'grey darken-4' : 'primary'"
+ :color="$vuetify.breakpoint.lgAndUp ? 'grey darken-4' : 'black'"
>
- <div>
+ <div :class="{ 'px-2': $vuetify.breakpoint.mdAndDown }">
<v-toolbar-title>
- <div class="d-flex" style="width: 225px">
+ <div class="d-flex pt-2" style="width: 225px">
<v-select
outlined
dense
+ :disabled="owners.length === 0"
+ placeholder="Phone Numbers"
+ :class="{ 'mb-n6': !$store.getters.getOwner }"
:items="owners"
:value="$store.getters.getOwner"
@change="onOwnerChanged"
@@ -27,7 +30,7 @@
</div>
</div>
</v-toolbar-title>
- <div class="d-flex mt-n4">
+ <div v-if="$store.getters.getOwner" class="d-flex mt-n4">
<p class="text--secondary mb-n1">
{{ $store.getters.getOwner | phoneCountry }}
</p>
@@ -58,12 +61,28 @@
<v-spacer></v-spacer>
<v-menu offset-y>
<template #activator="{ on }">
- <v-btn icon text v-on="on">
+ <v-btn icon text class="mt-2" v-on="on">
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</template>
<v-list class="px-2" nav :dense="$vuetify.breakpoint.mdAndDown">
<v-list-item-group>
+ <v-list-item
+ v-if="$store.getters.getOwner"
+ :to="{ name: 'messages' }"
+ exact
+ >
+ <v-list-item-icon class="pl-2">
+ <v-icon dense>mdi-plus</v-icon>
+ </v-list-item-icon>
+ <v-list-item-content class="ml-n3">
+ <v-list-item-title class="pr-16 py-1">
+ <span :class="{ 'pr-16': $vuetify.breakpoint.mdAndUp }">
+ New Message
+ </span>
+ </v-list-item-title>
+ </v-list-item-content>
+ </v-list-item>
<v-list-item :to="{ name: 'settings' }" exact>
<v-list-item-icon class="pl-2">
<v-icon dense>mdi-account-cog</v-icon>
@@ -76,6 +95,22 @@
</v-list-item-title>
</v-list-item-content>
</v-list-item>
+ <v-list-item
+ v-if="$store.getters.getOwner"
+ :href="$store.getters.getAppData.appDownloadUrl"
+ exact
+ >
+ <v-list-item-icon class="pl-2">
+ <v-icon dense>mdi-download</v-icon>
+ </v-list-item-icon>
+ <v-list-item-content class="ml-n3">
+ <v-list-item-title class="pr-16 py-1">
+ <span :class="{ 'pr-16': $vuetify.breakpoint.mdAndUp }">
+ Install App
+ </span>
+ </v-list-item-title>
+ </v-list-item-content>
+ </v-list-item>
<v-list-item @click.prevent="logout">
<v-list-item-icon class="pl-2">
<v-icon dense>mdi-logout</v-icon>
@@ -111,7 +146,6 @@ export default class MessageThreadHeader extends Vue {
}
async onOwnerChanged(owner: string) {
- console.log('owner changed')
await this.$store.dispatch('setOwner', owner)
if (this.$route.name !== 'threads') {
await this.$store.dispatch('setThreadId', null)
diff --git a/web/layouts/default.vue b/web/layouts/default.vue
index 37905904..771ef478 100644
--- a/web/layouts/default.vue
+++ b/web/layouts/default.vue
@@ -26,7 +26,7 @@ export default class DefaultLayout extends Vue {
poller: number | null = null
get hasDrawer(): boolean {
- return !['login', 'index', 'settings'].includes(this.$route.name ?? '')
+ return ['threads', 'threads-id'].includes(this.$route.name ?? '')
}
mounted() {
@@ -44,14 +44,17 @@ export default class DefaultLayout extends Vue {
await this.$store.dispatch('setPolling', true)
const promises = []
- if (this.$store.getters.getUser && this.$store.getters.getOwner) {
+ if (this.$store.getters.getAuthUser && this.$store.getters.getOwner) {
promises.push(
this.$store.dispatch('loadThreads'),
- this.$store.dispatch('getHeartbeat'),
- this.$store.dispatch('loadPhones', true)
+ this.$store.dispatch('getHeartbeat')
)
}
+ if (this.$store.getters.getAuthUser) {
+ promises.push(this.$store.dispatch('loadPhones', true))
+ }
+
if (this.$store.getters.hasThread && this.$store.getters.getUser) {
promises.push(
this.$store.dispatch(
diff --git a/web/pages/messages/index.vue b/web/pages/messages/index.vue
new file mode 100644
index 00000000..c09ab732
--- /dev/null
+++ b/web/pages/messages/index.vue
@@ -0,0 +1,109 @@
+<template>
+ <v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp">
+ <div class="w-full h-full">
+ <v-app-bar :dense="$vuetify.breakpoint.mdAndDown">
+ <v-btn icon to="/">
+ <v-icon>mdi-arrow-left</v-icon>
+ </v-btn>
+ <v-toolbar-title>New Message</v-toolbar-title>
+ </v-app-bar>
+ <v-container>
+ <v-row>
+ <v-col cols="12" md="8" offset-md="2" xl="6" offset-xl="3">
+ <v-form @submit.prevent="sendMessage">
+ <v-text-field
+ v-model="formPhoneNumber"
+ :disabled="sending"
+ :error="errors.has('to')"
+ :error-messages="errors.get('to')"
+ outlined
+ placeholder="Recipient phone number e.g +18005550199"
+ label="Phone Number"
+ ></v-text-field>
+ <v-textarea
+ v-model="formContent"
+ :error="errors.has('content')"
+ :error-messages="errors.get('content')"
+ :disabled="sending"
+ outlined
+ placeholder="Enter your message here"
+ label="Content"
+ ></v-textarea>
+ <v-btn
+ type="submit"
+ class="primary"
+ :disabled="sending"
+ :block="$vuetify.breakpoint.mdAndDown"
+ >
+ <v-icon>mdi-send</v-icon>
+ Send Message
+ </v-btn>
+ </v-form>
+ </v-col>
+ </v-row>
+ </v-container>
+ </div>
+ </v-container>
+</template>
+
+<script>
+import axios from '@/plugins/axios'
+
+export default {
+ name: 'MessagesIndex',
+ middleware: ['auth'],
+ data() {
+ return {
+ sending: false,
+ formPhoneNumber: '',
+ formContent: '',
+ errors: new Map(),
+ }
+ },
+
+ methods: {
+ sendMessage() {
+ this.errors = new Map()
+ this.sending = true
+ axios
+ .post('/v1/messages/send', {
+ to: this.formPhoneNumber,
+ from: this.$store.getters.getOwner,
+ content: this.formContent,
+ })
+ .then(() => {
+ this.$store.dispatch('addNotification', {
+ message: 'Message Sent!',
+ type: 'success',
+ })
+ this.$router.push({ name: 'threads' })
+ })
+ .catch((axiosError) => {
+ const errors = new Map()
+ const response = axiosError.response
+ if (response.data.data.content) {
+ errors.set('content', response.data.data.content)
+ }
+ if (response.data.data.to) {
+ errors.set(
+ 'to',
+ response.data.data.to.map((x) =>
+ x.replace('to field', 'phone number field')
+ )
+ )
+ }
+ if (response.data.data.from) {
+ this.$store.dispatch('addNotification', {
+ message: response.data.data.from[0],
+ type: 'error',
+ })
+ }
+ this.errors = errors
+ })
+ .finally(() => {
+ this.sending = false
+ })
+ },
+ },
+}
+</script>
diff --git a/web/store/index.ts b/web/store/index.ts
index db60af6f..c71ff192 100644
--- a/web/store/index.ts
+++ b/web/store/index.ts
@@ -64,6 +64,7 @@ export const state = (): State => ({
export type AppData = {
url: string
name: string
+ appDownloadUrl: string
documentationUrl: string
githubUrl: string
}
@@ -80,6 +81,7 @@ export const getters = {
}
return {
url,
+ appDownloadUrl: process.env.APP_DOWNLOAD_URL as string,
documentationUrl: process.env.APP_DOCUMENTATION_URL as string,
githubUrl: process.env.APP_GITHUB_URL as string,
name: process.env.APP_NAME as string,
@@ -211,6 +213,11 @@ export type SendMessageRequest = {
export const actions = {
async loadThreads(context: ActionContext<State, State>) {
+ if (context.getters.getOwner === null) {
+ await context.commit('setThreads', [])
+ return
+ }
+
const response = await axios.get('/v1/message-threads', {
params: {
owner: context.getters.getOwner,
diff --git a/web/types.d.ts b/web/types.d.ts
index 8aefc6e0..ea5ed961 100644
--- a/web/types.d.ts
+++ b/web/types.d.ts
@@ -1,5 +1,5 @@
import firebase from 'firebase/compat'
-import Vuetify from 'vuetify/lib'
+import { Framework } from 'vuetify'
interface Firebase {
auth: firebase.auth.Auth
@@ -14,7 +14,7 @@ export interface SelectItem {
declare module 'vue/types/vue' {
interface Vue {
- $vuetify: typeof Vuetify
+ $vuetify: Framework
$fire: Firebase
}
}