Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download web/app/stores/messages.ts from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/stores/messages.ts
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/web/app/stores/messages.ts
-
curl -L -o messages.ts https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/stores/messages.ts
2.83 kB
| import { defineStore } from 'pinia' | |
| import type { EntitiesMessage, EntitiesBulkMessage } from '~~/shared/types/api' | |
| import type { SearchMessagesRequest } from '~~/shared/types/message' | |
| import { getApiErrorMessage } from '~/utils/api-error' | |
| export type SIM = 'SIM1' | 'SIM2' | 'DEFAULT' | |
| export interface SendMessageRequest { | |
| from: string | |
| to: string | |
| content: string | |
| sim: SIM | |
| request_id?: string | |
| } | |
| export const useMessagesStore = defineStore('messages', () => { | |
| const { apiFetch } = useApi() | |
| const notificationsStore = useNotificationsStore() | |
| async function sendMessage(request: SendMessageRequest) { | |
| try { | |
| const response = await apiFetch<{ message: string }>( | |
| '/v1/messages/send', | |
| { | |
| method: 'POST', | |
| body: request, | |
| }, | |
| ) | |
| notificationsStore.addNotification({ | |
| message: response.message, | |
| type: 'success', | |
| }) | |
| } catch (e: unknown) { | |
| notificationsStore.addNotification({ | |
| message: getApiErrorMessage(e, 'Error while sending message'), | |
| type: 'error', | |
| }) | |
| } | |
| const threadsStore = useThreadsStore() | |
| await threadsStore.loadThreads() | |
| } | |
| async function deleteMessage(messageId: string) { | |
| await apiFetch(`/v1/messages/${messageId}`, { method: 'DELETE' }) | |
| notificationsStore.addNotification({ | |
| message: 'The message has been deleted successfully', | |
| type: 'success', | |
| }) | |
| } | |
| async function getMessage(messageId: string): Promise<EntitiesMessage> { | |
| const response = await apiFetch<{ data: EntitiesMessage }>( | |
| `/v1/messages/${messageId}`, | |
| ) | |
| return response.data | |
| } | |
| async function searchMessages( | |
| payload: SearchMessagesRequest, | |
| ): Promise<EntitiesMessage[]> { | |
| const token = payload.token | |
| const params = { ...payload } | |
| delete params.token | |
| const response = await apiFetch<{ data: EntitiesMessage[] }>( | |
| '/v1/messages/search', | |
| { | |
| params, | |
| headers: token ? { token } : undefined, | |
| }, | |
| ) | |
| return response.data | |
| } | |
| async function sendBulkMessages(document: File): Promise<void> { | |
| const formData = new FormData() | |
| formData.append('document', document) | |
| const response = await apiFetch<{ message?: string }>('/v1/bulk-messages', { | |
| method: 'POST', | |
| body: formData, | |
| }) | |
| notificationsStore.addNotification({ | |
| message: response.message ?? 'Bulk messages sent successfully', | |
| type: 'success', | |
| }) | |
| } | |
| async function fetchBulkMessageOrders(): Promise<EntitiesBulkMessage[]> { | |
| const response = await apiFetch<{ data: EntitiesBulkMessage[] }>( | |
| '/v1/bulk-messages', | |
| ) | |
| return response.data ?? [] | |
| } | |
| return { | |
| sendMessage, | |
| deleteMessage, | |
| getMessage, | |
| searchMessages, | |
| sendBulkMessages, | |
| fetchBulkMessageOrders, | |
| } | |
| }) | |