Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Progress
Acho Arnold3ff4830bfd28
diff --git a/api/pkg/handlers/events_handler.go b/api/pkg/handlers/events_handler.goindex 02b4fcce..631d8fa3 100644--- a/api/pkg/handlers/events_handler.go+++ b/api/pkg/handlers/events_handler.go@@ -63,14 +63,14 @@ func (h *EventsHandler) Dispatch(c *fiber.Ctx) error {}if h.userIDFomContext(c) != h.queueConfig.UserID {- msg := fmt.Sprintf("user with MessageID [%s], cannot dispatch event [%+#v]", h.userIDFomContext(c), request)+ msg := fmt.Sprintf("user with ID [%s], cannot dispatch event [%+#v]", h.userIDFomContext(c), request)ctxLogger.Error(stacktrace.NewError(msg))return h.responseForbidden(c)}err := h.service.Dispatch(ctx, request)if err != nil {- msg := fmt.Sprintf("cannot dispatch event with MessageID [%s]", request.ID())+ msg := fmt.Sprintf("cannot dispatch event with ID [%s]", request.ID())ctxLogger.Error(stacktrace.Propagate(err, msg))return h.responseInternalServerError(c)}diff --git a/api/pkg/handlers/message_handler.go b/api/pkg/handlers/message_handler.goindex 9621e9b7..f9d230a7 100644--- a/api/pkg/handlers/message_handler.go+++ b/api/pkg/handlers/message_handler.go@@ -100,7 +100,7 @@ func (h *MessageHandler) PostSend(c *fiber.Ctx) error {// @Tags Messages// @Accept json// @Produce json-// @Param message_id query string true "The MessageID of the message" default(32343a19-da5e-4b1b-a767-3298a73703cb)+// @Param message_id query string true "The ID of the message" default(32343a19-da5e-4b1b-a767-3298a73703cb)// @Success 200 {object} responses.MessageResponse// @Failure 400 {object} responses.BadRequest// @Failure 401 {object} responses.Unauthorized@@ -129,7 +129,7 @@ func (h *MessageHandler) GetOutstanding(c *fiber.Ctx) error {message, err := h.service.GetOutstanding(ctx, request.ToGetOutstandingParams(c.OriginalURL(), h.userIDFomContext(c), timestamp))if err != nil {- msg := fmt.Sprintf("cannot get outstnading messgage with MessageID [%s]", request.MessageID)+ msg := fmt.Sprintf("cannot get outstnading messgage with ID [%s]", request.MessageID)ctxLogger.Error(stacktrace.Propagate(err, msg))return h.responseInternalServerError(c)}@@ -191,7 +191,7 @@ func (h *MessageHandler) Index(c *fiber.Ctx) error {// @Tags Messages// @Accept json// @Produce json-// @Param messageID path string true "MessageID of the message" default(32343a19-da5e-4b1b-a767-3298a73703ca)+// @Param messageID path string true "ID of the message" default(32343a19-da5e-4b1b-a767-3298a73703ca)// @Param payload body requests.MessageEvent true "Payload of the event emitted."// @Success 200 {object} responses.MessageResponse// @Failure 400 {object} responses.BadRequest@@ -223,7 +223,7 @@ func (h *MessageHandler) PostEvent(c *fiber.Ctx) error {message, err := h.service.GetMessage(ctx, h.userIDFomContext(c), uuid.MustParse(request.MessageID))if err != nil && stacktrace.GetCode(err) == repositories.ErrCodeNotFound {- return h.responseNotFound(c, fmt.Sprintf("cannot find message with MessageID [%s]", request.MessageID))+ return h.responseNotFound(c, fmt.Sprintf("cannot find message with ID [%s]", request.MessageID))}if err != nil {diff --git a/api/pkg/handlers/phone_handler.go b/api/pkg/handlers/phone_handler.goindex 723c2dce..df7b8175 100644--- a/api/pkg/handlers/phone_handler.go+++ b/api/pkg/handlers/phone_handler.go@@ -139,7 +139,7 @@ func (h *PhoneHandler) Upsert(c *fiber.Ctx) error {// @Tags Phones// @Accept json// @Produce json-// @Param phoneID path string true "MessageID of the phone" default(32343a19-da5e-4b1b-a767-3298a73703ca)+// @Param phoneID path string true "ID of the phone" default(32343a19-da5e-4b1b-a767-3298a73703ca)// @Success 204 {object} responses.NoContent// @Failure 400 {object} responses.BadRequest// @Failure 401 {object} responses.Unauthorizeddiff --git a/api/pkg/handlers/user_handler.go b/api/pkg/handlers/user_handler.goindex 881380a0..7c464a64 100644--- a/api/pkg/handlers/user_handler.go+++ b/api/pkg/handlers/user_handler.go@@ -66,7 +66,7 @@ func (h *UserHandler) Show(c *fiber.Ctx) error {user, err := h.service.Get(ctx, authUser)if err != nil {- msg := fmt.Sprintf("cannot get user with MessageID [%s]", authUser.ID)+ msg := fmt.Sprintf("cannot get user with ID [%s]", authUser.ID)ctxLogger.Error(stacktrace.Propagate(err, msg))return h.responseInternalServerError(c)}diff --git a/api/pkg/repositories/gorm_event_listener_log_repository.go b/api/pkg/repositories/gorm_event_listener_log_repository.goindex 37c9f699..5b909620 100644--- a/api/pkg/repositories/gorm_event_listener_log_repository.go+++ b/api/pkg/repositories/gorm_event_listener_log_repository.go@@ -36,7 +36,7 @@ func (repository *gormEventListenerLogRepository) Store(ctx context.Context, mesdefer span.End()if err := repository.db.WithContext(ctx).Create(message).Error; err != nil {- msg := fmt.Sprintf("cannot save message with MessageID [%s]", message.ID)+ msg := fmt.Sprintf("cannot save message with ID [%s]", message.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -56,7 +56,7 @@ func (repository *gormEventListenerLogRepository) Has(ctx context.Context, eventFind(&exists).Errorif err != nil {- msg := fmt.Sprintf("cannot check if log exists with event MessageID [%s] and handler [%s]", eventID, handler)+ msg := fmt.Sprintf("cannot check if log exists with event ID [%s] and handler [%s]", eventID, handler)return exists, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}diff --git a/api/pkg/repositories/gorm_heartbeat_repository.go b/api/pkg/repositories/gorm_heartbeat_repository.goindex c57969b4..9aa1dd0e 100644--- a/api/pkg/repositories/gorm_heartbeat_repository.go+++ b/api/pkg/repositories/gorm_heartbeat_repository.go@@ -56,7 +56,7 @@ func (repository *gormHeartbeatRepository) Store(ctx context.Context, heartbeatdefer span.End()if err := repository.db.WithContext(ctx).Create(heartbeat).Error; err != nil {- msg := fmt.Sprintf("cannot save heartbeat with MessageID [%s]", heartbeat.ID)+ msg := fmt.Sprintf("cannot save heartbeat with ID [%s]", heartbeat.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}diff --git a/api/pkg/repositories/gorm_message_repository.go b/api/pkg/repositories/gorm_message_repository.goindex e8efb231..b23973dc 100644--- a/api/pkg/repositories/gorm_message_repository.go+++ b/api/pkg/repositories/gorm_message_repository.go@@ -65,14 +65,14 @@ func (repository *gormMessageRepository) Store(ctx context.Context, message *entdefer span.End()if err := repository.db.WithContext(ctx).Create(message).Error; err != nil {- msg := fmt.Sprintf("cannot save message with MessageID [%s]", message.ID)+ msg := fmt.Sprintf("cannot save message with ID [%s]", message.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}return nil}-// Load an entities.Message by MessageID+// Load an entities.Message by IDfunc (repository *gormMessageRepository) Load(ctx context.Context, userID entities.UserID, messageID uuid.UUID) (*entities.Message, error) {ctx, span := repository.tracer.Start(ctx)defer span.End()@@ -80,12 +80,12 @@ func (repository *gormMessageRepository) Load(ctx context.Context, userID entitimessage := new(entities.Message)err := repository.db.WithContext(ctx).Where("user_id = ?", userID).Where("id = ?", messageID).First(message).Errorif errors.Is(err, gorm.ErrRecordNotFound) {- msg := fmt.Sprintf("message with MessageID [%s] and userID [%s] does not exist", messageID, userID)+ msg := fmt.Sprintf("message with ID [%s] and userID [%s] does not exist", messageID, userID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))}if err != nil {- msg := fmt.Sprintf("cannot load message with MessageID [%s]", messageID)+ msg := fmt.Sprintf("cannot load message with ID [%s]", messageID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -98,7 +98,7 @@ func (repository *gormMessageRepository) Update(ctx context.Context, message *endefer span.End()if err := repository.db.WithContext(ctx).Save(message).Error; err != nil {- msg := fmt.Sprintf("cannot update message with MessageID [%s]", message.ID)+ msg := fmt.Sprintf("cannot update message with ID [%s]", message.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}diff --git a/api/pkg/repositories/gorm_message_thread_repository.go b/api/pkg/repositories/gorm_message_thread_repository.goindex a482229a..10ab9a8e 100644--- a/api/pkg/repositories/gorm_message_thread_repository.go+++ b/api/pkg/repositories/gorm_message_thread_repository.go@@ -41,7 +41,7 @@ func (repository *gormMessageThreadRepository) Store(ctx context.Context, threaddefer span.End()if err := repository.db.WithContext(ctx).Clauses(clause.OnConflict{DoNothing: true}).Create(thread).Error; err != nil {- msg := fmt.Sprintf("cannot save message thread with MessageID [%s]", thread.ID)+ msg := fmt.Sprintf("cannot save message thread with ID [%s]", thread.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -54,7 +54,7 @@ func (repository *gormMessageThreadRepository) Update(ctx context.Context, threadefer span.End()if err := repository.db.WithContext(ctx).Save(thread).Error; err != nil {- msg := fmt.Sprintf("cannot update message thread thread with MessageID [%s]", thread.ID)+ msg := fmt.Sprintf("cannot update message thread thread with ID [%s]", thread.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -88,7 +88,7 @@ func (repository *gormMessageThreadRepository) LoadByOwnerContact(ctx context.Coreturn thread, nil}-// Load an entities.MessageThread by MessageID+// Load an entities.MessageThread by IDfunc (repository *gormMessageThreadRepository) Load(ctx context.Context, userID entities.UserID, ID uuid.UUID) (*entities.MessageThread, error) {ctx, span := repository.tracer.Start(ctx)defer span.End()diff --git a/api/pkg/repositories/gorm_phone_notification_repository.go b/api/pkg/repositories/gorm_phone_notification_repository.goindex 7159c38f..f005eec1 100644--- a/api/pkg/repositories/gorm_phone_notification_repository.go+++ b/api/pkg/repositories/gorm_phone_notification_repository.go@@ -70,7 +70,7 @@ func (repository gormPhoneNotificationRepository) Schedule(ctx context.Context,First(lastNotification).Errorif err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {- msg := fmt.Sprintf("cannot fetch last notification with phone MessageID [%s]", notification.PhoneID)+ msg := fmt.Sprintf("cannot fetch last notification with phone ID [%s]", notification.PhoneID)return stacktrace.Propagate(err, msg)}@@ -89,7 +89,7 @@ func (repository gormPhoneNotificationRepository) Schedule(ctx context.Context,return nil})if err != nil {- msg := fmt.Sprintf("cannot schedule phone notification with MessageID [%s]", notification.ID)+ msg := fmt.Sprintf("cannot schedule phone notification with ID [%s]", notification.ID)return stacktrace.Propagate(err, msg)}diff --git a/api/pkg/repositories/gorm_phone_repository.go b/api/pkg/repositories/gorm_phone_repository.goindex e568f330..c8f06c9e 100644--- a/api/pkg/repositories/gorm_phone_repository.go+++ b/api/pkg/repositories/gorm_phone_repository.go@@ -33,7 +33,7 @@ func NewGormPhoneRepository(}}-// LoadByID loads a phone by MessageID+// LoadByID loads a phone by IDfunc (repository *gormPhoneRepository) LoadByID(ctx context.Context, phoneID uuid.UUID) (*entities.Phone, error) {ctx, span := repository.tracer.Start(ctx)defer span.End()@@ -41,12 +41,12 @@ func (repository *gormPhoneRepository) LoadByID(ctx context.Context, phoneID uuiphone := new(entities.Phone)err := repository.db.WithContext(ctx).First(phone, phoneID).Errorif errors.Is(err, gorm.ErrRecordNotFound) {- msg := fmt.Sprintf("phone with MessageID [%s] does not exist", phoneID)+ msg := fmt.Sprintf("phone with ID [%s] does not exist", phoneID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))}if err != nil {- msg := fmt.Sprintf("cannot load phone with MessageID [%s]", phoneID)+ msg := fmt.Sprintf("cannot load phone with ID [%s]", phoneID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -63,7 +63,7 @@ func (repository *gormPhoneRepository) Delete(ctx context.Context, userID entitiWhere("id = ?", phoneID).Delete(&entities.Phone{}).Errorif err != nil {- msg := fmt.Sprintf("cannot delete phone with MessageID [%s] and userID [%s]", phoneID, userID)+ msg := fmt.Sprintf("cannot delete phone with ID [%s] and userID [%s]", phoneID, userID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -76,7 +76,7 @@ func (repository *gormPhoneRepository) Save(ctx context.Context, phone *entitiesdefer span.End()if err := repository.db.WithContext(ctx).Save(phone).Error; err != nil {- msg := fmt.Sprintf("cannot save phone with MessageID [%s]", phone.ID)+ msg := fmt.Sprintf("cannot save phone with ID [%s]", phone.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}diff --git a/api/pkg/repositories/gorm_user_repository.go b/api/pkg/repositories/gorm_user_repository.goindex bd82ccfc..705d3189 100644--- a/api/pkg/repositories/gorm_user_repository.go+++ b/api/pkg/repositories/gorm_user_repository.go@@ -41,7 +41,7 @@ func (repository *gormUserRepository) Store(ctx context.Context, user *entities.defer span.End()if err := repository.db.WithContext(ctx).Create(user).Error; err != nil {- msg := fmt.Sprintf("cannot save user with MessageID [%s]", user.ID)+ msg := fmt.Sprintf("cannot save user with ID [%s]", user.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -53,7 +53,7 @@ func (repository *gormUserRepository) Update(ctx context.Context, user *entitiesdefer span.End()if err := repository.db.WithContext(ctx).Save(user).Error; err != nil {- msg := fmt.Sprintf("cannot update user with MessageID [%s]", user.ID)+ msg := fmt.Sprintf("cannot update user with ID [%s]", user.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}@@ -89,12 +89,12 @@ func (repository *gormUserRepository) Load(ctx context.Context, userID entities.user := new(entities.User)err := repository.db.WithContext(ctx).First(user, userID).Errorif errors.Is(err, gorm.ErrRecordNotFound) {- msg := fmt.Sprintf("user with MessageID [%s] does not exist", user.ID)+ msg := fmt.Sprintf("user with ID [%s] does not exist", user.ID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))}if err != nil {- msg := fmt.Sprintf("cannot load user with MessageID [%s]", userID)+ msg := fmt.Sprintf("cannot load user with ID [%s]", userID)return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}diff --git a/api/pkg/repositories/message_repository.go b/api/pkg/repositories/message_repository.goindex 07dc9959..4277cfcb 100644--- a/api/pkg/repositories/message_repository.go+++ b/api/pkg/repositories/message_repository.go@@ -15,7 +15,7 @@ type MessageRepository interface {// Update a new entities.MessageUpdate(ctx context.Context, message *entities.Message) error- // Load an entities.Message by MessageID+ // Load an entities.Message by IDLoad(ctx context.Context, userID entities.UserID, messageID uuid.UUID) (*entities.Message, error)// Index entities.Message between 2 phone numbersdiff --git a/api/pkg/repositories/message_thread_repository.go b/api/pkg/repositories/message_thread_repository.goindex 2ebcabdf..c695e976 100644--- a/api/pkg/repositories/message_thread_repository.go+++ b/api/pkg/repositories/message_thread_repository.go@@ -19,7 +19,7 @@ type MessageThreadRepository interface {// LoadByOwnerContact fetches a thread between owner and contactLoadByOwnerContact(ctx context.Context, userID entities.UserID, owner string, contact string) (*entities.MessageThread, error)- // Load a thread by MessageID+ // Load a thread by IDLoad(ctx context.Context, userID entities.UserID, ID uuid.UUID) (*entities.MessageThread, error)// Index message threads for an ownerdiff --git a/api/pkg/repositories/phone_repository.go b/api/pkg/repositories/phone_repository.goindex 5b452a93..fcdd0385 100644--- a/api/pkg/repositories/phone_repository.go+++ b/api/pkg/repositories/phone_repository.go@@ -19,7 +19,7 @@ type PhoneRepository interface {// Load a phone by user and phone numberLoad(ctx context.Context, userID entities.UserID, phoneNumber string) (*entities.Phone, error)- // LoadByID a phone by MessageID+ // LoadByID a phone by IDLoadByID(ctx context.Context, phoneID uuid.UUID) (*entities.Phone, error)// Delete an entities.Phone