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 api/pkg/requests/message_receive_request.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/requests/message_receive_request.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway@6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/requests/message_receive_request.go
-
curl -L -o message_receive_request.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/requests/message_receive_request.go
2.68 kB
| package requests | |
| import ( | |
| "strings" | |
| "time" | |
| "github.com/NdoleStudio/httpsms/pkg/entities" | |
| "github.com/nyaruka/phonenumbers" | |
| "github.com/NdoleStudio/httpsms/pkg/services" | |
| ) | |
| // MessageAttachment represents a single MMS attachment in a receive request | |
| type MessageAttachment struct { | |
| // Name is the original filename of the attachment | |
| Name string `json:"name" example:"photo.jpg"` | |
| // ContentType is the MIME type of the attachment | |
| ContentType string `json:"content_type" example:"image/jpeg"` | |
| // Content is the base64-encoded attachment data | |
| Content string `json:"content" example:"base64data..."` | |
| } | |
| // MessageReceive is the payload for sending and SMS message | |
| type MessageReceive struct { | |
| request | |
| From string `json:"from" example:"+18005550199"` | |
| To string `json:"to" example:"+18005550100"` | |
| Content string `json:"content" example:"This is a sample text message received on a phone"` | |
| // Encrypted is used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app | |
| Encrypted bool `json:"encrypted" example:"false"` | |
| // SIM card that received the message | |
| SIM entities.SIM `json:"sim" example:"SIM1"` | |
| // Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible | |
| Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"` | |
| // Attachments is the list of MMS attachments received with the message | |
| Attachments []MessageAttachment `json:"attachments" validate:"optional"` | |
| } | |
| // Sanitize sets defaults to MessageReceive | |
| func (input *MessageReceive) Sanitize() MessageReceive { | |
| input.To = input.sanitizeAddress(input.To) | |
| input.From = input.sanitizeContact(input.To, input.From) | |
| if strings.TrimSpace(string(input.SIM)) == "" || input.SIM == ("DEFAULT") { | |
| input.SIM = entities.SIM1 | |
| } | |
| return *input | |
| } | |
| // ToMessageReceiveParams converts MessageReceive to services.MessageReceiveParams | |
| func (input *MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) *services.MessageReceiveParams { | |
| phone, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION) | |
| attachments := make([]services.ServiceAttachment, len(input.Attachments)) | |
| for i, a := range input.Attachments { | |
| attachments[i] = services.ServiceAttachment{ | |
| Name: a.Name, | |
| ContentType: a.ContentType, | |
| Content: a.Content, | |
| } | |
| } | |
| return &services.MessageReceiveParams{ | |
| Source: source, | |
| Contact: input.From, | |
| UserID: userID, | |
| Timestamp: input.Timestamp, | |
| Encrypted: input.Encrypted, | |
| Owner: phone, | |
| Content: input.Content, | |
| SIM: input.SIM, | |
| Attachments: attachments, | |
| } | |
| } | |