Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Add ability to delete messages on the web UI #322
Acho Arnold4c6d89d3ef3d
diff --git a/api/docs/docs.go b/api/docs/docs.goindex cf4df174..68754a48 100644--- a/api/docs/docs.go+++ b/api/docs/docs.go@@ -161,7 +161,7 @@ const docTemplate = `{"tags": ["BulkSMS"],- "summary": "Save bulk SMS file",+ "summary": "Store bulk SMS file","responses": {"202": {"description": "Accepted",@@ -276,7 +276,7 @@ const docTemplate = `{"ApiKeyAuth": []}],- "description": "Save a discord integration for the authenticated user",+ "description": "Store a discord integration for the authenticated user","consumes": ["application/json"],@@ -286,7 +286,7 @@ const docTemplate = `{"tags": ["DiscordIntegration"],- "summary": "Save discord integration",+ "summary": "Store discord integration","parameters": [{"description": "Payload of the discord integration request",@@ -598,7 +598,7 @@ const docTemplate = `{"ApiKeyAuth": []}],- "description": "Save the heartbeat to make notify that a phone number is still active",+ "description": "Store the heartbeat to make notify that a phone number is still active","consumes": ["application/json"],@@ -1241,6 +1241,74 @@ const docTemplate = `{}}},+ "/messages/{messageID}": {+ "delete": {+ "security": [+ {+ "ApiKeyAuth": []+ }+ ],+ "description": "Delete a message from the database and removes the message content from the list of threads.",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Messages"+ ],+ "summary": "Delete a message from the database.",+ "parameters": [+ {+ "type": "string",+ "default": "32343a19-da5e-4b1b-a767-3298a73703ca",+ "description": "ID of the message",+ "name": "messageID",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "204": {+ "description": "No Content",+ "schema": {+ "$ref": "#/definitions/responses.NoContent"+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/responses.BadRequest"+ }+ },+ "401": {+ "description": "Unauthorized",+ "schema": {+ "$ref": "#/definitions/responses.Unauthorized"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/responses.NotFound"+ }+ },+ "422": {+ "description": "Unprocessable Entity",+ "schema": {+ "$ref": "#/definitions/responses.UnprocessableEntity"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/responses.InternalServerError"+ }+ }+ }+ }+ },"/messages/{messageID}/events": {"post": {"security": [@@ -1878,7 +1946,7 @@ const docTemplate = `{"ApiKeyAuth": []}],- "description": "Save a webhook for the authenticated user",+ "description": "Store a webhook for the authenticated user","consumes": ["application/json"],@@ -1888,7 +1956,7 @@ const docTemplate = `{"tags": ["Webhooks"],- "summary": "Save a webhook",+ "summary": "Store a webhook","parameters": [{"description": "Payload of the webhook request",@@ -2218,6 +2286,7 @@ const docTemplate = `{"request_id","request_received_at","scheduled_at",+ "scheduled_send_time","send_attempt_count","send_time","sent_at",@@ -2296,6 +2365,10 @@ const docTemplate = `{"type": "string","example": "2022-06-05T14:26:09.527976+03:00"},+ "scheduled_send_time": {+ "type": "string",+ "example": "2022-06-05T14:26:09.527976+03:00"+ },"send_attempt_count": {"type": "integer","example": 0@@ -2481,7 +2554,9 @@ const docTemplate = `{"ultra-yearly","pro-lifetime","20k-monthly",- "20k-yearly"+ "100k-monthly",+ "20k-yearly",+ "100k-yearly"],"x-enum-varnames": ["SubscriptionNameFree",@@ -2491,7 +2566,9 @@ const docTemplate = `{"SubscriptionNameUltraYearly","SubscriptionNameProLifetime","SubscriptionName20KMonthly",- "SubscriptionName20KYearly"+ "SubscriptionName100KMonthly",+ "SubscriptionName20KYearly",+ "SubscriptionName100KYearly"]},"entities.User": {@@ -2807,6 +2884,11 @@ const docTemplate = `{"type": "string","example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4"},+ "send_at": {+ "description": "SendAt is an optional parameter used to schedule a message to be sent at a later time",+ "type": "string",+ "example": "2022-06-05T14:26:09.527976+03:00"+ },"to": {"type": "string","example": "+18005550100"diff --git a/api/docs/swagger.json b/api/docs/swagger.jsonindex 30900e4d..7931b4f7 100644--- a/api/docs/swagger.json+++ b/api/docs/swagger.json@@ -1121,6 +1121,68 @@}}},+ "/messages/{messageID}": {+ "delete": {+ "security": [+ {+ "ApiKeyAuth": []+ }+ ],+ "description": "Delete a message from the database and removes the message content from the list of threads.",+ "consumes": ["application/json"],+ "produces": ["application/json"],+ "tags": ["Messages"],+ "summary": "Delete a message from the database.",+ "parameters": [+ {+ "type": "string",+ "default": "32343a19-da5e-4b1b-a767-3298a73703ca",+ "description": "ID of the message",+ "name": "messageID",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "204": {+ "description": "No Content",+ "schema": {+ "$ref": "#/definitions/responses.NoContent"+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/responses.BadRequest"+ }+ },+ "401": {+ "description": "Unauthorized",+ "schema": {+ "$ref": "#/definitions/responses.Unauthorized"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/responses.NotFound"+ }+ },+ "422": {+ "description": "Unprocessable Entity",+ "schema": {+ "$ref": "#/definitions/responses.UnprocessableEntity"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/responses.InternalServerError"+ }+ }+ }+ }+ },"/messages/{messageID}/events": {"post": {"security": [@@ -2024,6 +2086,7 @@"request_id","request_received_at","scheduled_at",+ "scheduled_send_time","send_attempt_count","send_time","sent_at",@@ -2102,6 +2165,10 @@"type": "string","example": "2022-06-05T14:26:09.527976+03:00"},+ "scheduled_send_time": {+ "type": "string",+ "example": "2022-06-05T14:26:09.527976+03:00"+ },"send_attempt_count": {"type": "integer","example": 0@@ -2281,7 +2348,9 @@"ultra-yearly","pro-lifetime","20k-monthly",- "20k-yearly"+ "100k-monthly",+ "20k-yearly",+ "100k-yearly"],"x-enum-varnames": ["SubscriptionNameFree",@@ -2291,7 +2360,9 @@"SubscriptionNameUltraYearly","SubscriptionNameProLifetime","SubscriptionName20KMonthly",- "SubscriptionName20KYearly"+ "SubscriptionName100KMonthly",+ "SubscriptionName20KYearly",+ "SubscriptionName100KYearly"]},"entities.User": {@@ -2570,6 +2641,11 @@"type": "string","example": "153554b5-ae44-44a0-8f4f-7bbac5657ad4"},+ "send_at": {+ "description": "SendAt is an optional parameter used to schedule a message to be sent at a later time",+ "type": "string",+ "example": "2022-06-05T14:26:09.527976+03:00"+ },"to": {"type": "string","example": "+18005550100"diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yamlindex edcf52bf..e8ebcc36 100644--- a/api/docs/swagger.yaml+++ b/api/docs/swagger.yaml@@ -153,6 +153,9 @@ definitions:scheduled_at:example: "2022-06-05T14:26:09.527976+03:00"type: string+ scheduled_send_time:+ example: "2022-06-05T14:26:09.527976+03:00"+ type: stringsend_attempt_count:example: 0type: integer@@ -204,6 +207,7 @@ definitions:- request_id- request_received_at- scheduled_at+ - scheduled_send_time- send_attempt_count- send_time- sent_at@@ -330,7 +334,9 @@ definitions:- ultra-yearly- pro-lifetime- 20k-monthly+ - 100k-monthly- 20k-yearly+ - 100k-yearlytype: stringx-enum-varnames:- SubscriptionNameFree@@ -340,7 +346,9 @@ definitions:- SubscriptionNameUltraYearly- SubscriptionNameProLifetime- SubscriptionName20KMonthly+ - SubscriptionName100KMonthly- SubscriptionName20KYearly+ - SubscriptionName100KYearlyentities.User:properties:active_phone_id:@@ -578,6 +586,12 @@ definitions:the client's perspectiveexample: 153554b5-ae44-44a0-8f4f-7bbac5657ad4type: string+ send_at:+ description:+ SendAt is an optional parameter used to schedule a message to+ be sent at a later time+ example: "2022-06-05T14:26:09.527976+03:00"+ type: stringto:example: "+18005550100"type: string@@ -1690,6 +1704,52 @@ paths:summary: Get messages which are sent between 2 phone numberstags:- Messages+ /messages/{messageID}:+ delete:+ consumes:+ - application/json+ description:+ Delete a message from the database and removes the message content+ from the list of threads.+ parameters:+ - default: 32343a19-da5e-4b1b-a767-3298a73703ca+ description: ID of the message+ in: path+ name: messageID+ required: true+ type: string+ produces:+ - application/json+ responses:+ "204":+ description: No Content+ schema:+ $ref: "#/definitions/responses.NoContent"+ "400":+ description: Bad Request+ schema:+ $ref: "#/definitions/responses.BadRequest"+ "401":+ description: Unauthorized+ schema:+ $ref: "#/definitions/responses.Unauthorized"+ "404":+ description: Not Found+ schema:+ $ref: "#/definitions/responses.NotFound"+ "422":+ description: Unprocessable Entity+ schema:+ $ref: "#/definitions/responses.UnprocessableEntity"+ "500":+ description: Internal Server Error+ schema:+ $ref: "#/definitions/responses.InternalServerError"+ security:+ - ApiKeyAuth: []+ summary: Delete a message from the database.+ tags:+ - Messages/messages/{messageID}/events:post:consumes:diff --git a/web/pages/threads/_id/index.vue b/web/pages/threads/_id/index.vueindex dfa35441..9471f185 100644--- a/web/pages/threads/_id/index.vue+++ b/web/pages/threads/_id/index.vue@@ -95,7 +95,7 @@><v-icon>{{ mdiAccount }}</v-icon></v-avatar>- <v-menu v-if="canResend(message)" offset-y>+ <v-menu offset-y><template #activator="{ on }"><v-btn icon text class="mt-2" v-on="on"><v-icon>{{ mdiDotsVertical }}</v-icon>@@ -103,7 +103,10 @@</template><v-list class="px-2" nav dense><v-list-item-group v-model="selectedMenuItem">- <v-list-item @click.prevent="resendMessage(message)">+ <v-list-item+ v-if="canResend(message)"+ @click.prevent="resendMessage(message)"+ ><v-list-item-icon class="pl-2"><v-icon dense>{{ mdiRefresh }}</v-icon></v-list-item-icon>@@ -113,6 +116,16 @@</v-list-item-title></v-list-item-content></v-list-item>+ <v-list-item @click.prevent="deleteMessage(message)">+ <v-list-item-icon class="pl-2">+ <v-icon dense color="error">{{ mdiDelete }}</v-icon>+ </v-list-item-icon>+ <v-list-item-content class="ml-n3">+ <v-list-item-title class="pr-16 py-1">+ Delete Message+ </v-list-item-title>+ </v-list-item-content>+ </v-list-item></v-list-item-group></v-list></v-menu>@@ -243,6 +256,7 @@ import {mdiDotsVertical,mdiArrowLeft,mdiCheckAll,+ mdiDelete,mdiCheck,mdiAlert,mdiPackageUp,@@ -270,6 +284,7 @@ export default Vue.extend({mdiCheckAll,mdiCheck,mdiAlert,+ mdiDelete,hideMessages: true,loadingMessages: false,messages: [] as Message[],@@ -351,12 +366,12 @@ export default Vue.extend({.finally(() => {setTimeout(() => {this.loadingMessages = false- }, 900)+ }, 1100)})this.hideMessages = hideMessagessetTimeout(() => {this.scrollToElement()- }, 750)+ }, 950)},async loadData() {@@ -416,6 +431,16 @@ export default Vue.extend({this.loadMessages(false)},+ async deleteMessage(message: Message) {+ await this.$store.dispatch('deleteMessage', message.id)++ setTimeout(() => {+ this.selectedMenuItem = -1+ }, 1000)++ this.loadMessages(false)+ },+async sendMessage(event: KeyboardEvent) {if (event.shiftKey) {returndiff --git a/web/store/index.ts b/web/store/index.tsindex 621a6a34..d45b7a61 100644--- a/web/store/index.ts+++ b/web/store/index.ts@@ -485,6 +485,31 @@ export const actions = {await Promise.all([context.dispatch('loadThreads')])},+ deleteMessage(context: ActionContext<State, State>, messageId: string) {+ return new Promise<void>((resolve, reject) => {+ axios+ .delete<ResponsesNoContent>(`/v1/messages/${messageId}`)+ .then(async () => {+ await context.dispatch('addNotification', {+ message: 'The message has been deleted successfully',+ type: 'success',+ })+ resolve()+ })+ .catch(async (error: AxiosError) => {+ await Promise.all([+ context.dispatch('addNotification', {+ message:+ (error.response?.data as any)?.message ??+ 'Error while deleting message',+ type: 'error',+ }),+ ])+ reject(getErrorMessages(error))+ })+ })+ },+setThreadId(context: ActionContext<State, State>, threadId: string | null) {context.commit('setThreadId', threadId)},