Skip to content

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

Fix time

Acho Arnold90127e5599bd
diff --git a/api/pkg/repositories/gorm_phone_notification_repository.go b/api/pkg/repositories/gorm_phone_notification_repository.go
index a36bac07..fc8d1be6 100644
--- a/api/pkg/repositories/gorm_phone_notification_repository.go
+++ b/api/pkg/repositories/gorm_phone_notification_repository.go
@@ -99,7 +99,7 @@ func (repository *gormPhoneNotificationRepository) Schedule(
schedule *entities.MessageSendSchedule,
notification *entities.PhoneNotification,
) error {
- ctx, span := repository.tracer.Start(ctx)
+ ctx, span, _ := repository.tracer.StartWithLogger(ctx, repository.logger)
defer span.End()
now := time.Now().UTC()
@@ -174,7 +174,7 @@ func (repository *gormPhoneNotificationRepository) resolveScheduledAt(
return schedule.ResolveScheduledAt(current)
}
-// maxTime returns the later of the two times.
+// maxTime returns the greater of the two time.Time.
func (repository *gormPhoneNotificationRepository) maxTime(a, b time.Time) time.Time {
if a.After(b) {
return a
diff --git a/api/pkg/services/phone_notification_service.go b/api/pkg/services/phone_notification_service.go
index 63b62678..5da01f04 100644
--- a/api/pkg/services/phone_notification_service.go
+++ b/api/pkg/services/phone_notification_service.go
@@ -205,16 +205,16 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
var schedule *entities.MessageSendSchedule
if phone.MessageSendScheduleID != nil {
schedule, err = service.messageSendScheduleRepository.Load(ctx, params.UserID, *phone.MessageSendScheduleID)
- if stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
- schedule = nil
- err = nil
- }
- if err != nil {
+ if err != nil && stacktrace.GetCode(err) != repositories.ErrCodeNotFound {
msg := fmt.Sprintf("cannot load send schedule [%s] for phone [%s]", *phone.MessageSendScheduleID, phone.ID)
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
}
+ if schedule != nil {
+ ctxLogger.Info(fmt.Sprintf("loaded [%T] with ID [%s] for phone [%s]", schedule, schedule.ID, phone.ID))
+ }
+
if err = service.phoneNotificationRepository.Schedule(ctx, phone.MessagesPerMinute, schedule, notification); err != nil {
msg := fmt.Sprintf("cannot schedule notification for message [%s] to phone [%s]", params.MessageID, phone.ID)
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
@@ -229,10 +229,11 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
}
ctxLogger.Info(fmt.Sprintf(
- "message with id [%s] notification scheduled for [%s] with id [%s]",
+ "message with id [%s] notification scheduled for [%s] with id [%s] with phone schedule ID [%s]",
params.MessageID,
notification.ScheduledAt,
notification.ID,
+ phone.MessageSendScheduleID,
))
return nil
}
diff --git a/web/pages/settings/index.vue b/web/pages/settings/index.vue
index 6df69cd2..d24586fb 100644
--- a/web/pages/settings/index.vue
+++ b/web/pages/settings/index.vue
@@ -1126,8 +1126,8 @@ import { ErrorMessages } from '~/plugins/errors'
import LoadingButton from '~/components/LoadingButton.vue'
import {
EntitiesDiscord,
+ EntitiesMessageSendSchedule,
EntitiesPhone,
- EntitiesSendSchedule,
EntitiesWebhook,
} from '~/models/api'
@@ -1204,7 +1204,7 @@ export default Vue.extend({
updatingPhone: false,
updatingDiscord: false,
loadingDiscordIntegrations: false,
- sendSchedules: [] as EntitiesSendSchedule[],
+ sendSchedules: [] as EntitiesMessageSendSchedule[],
events: [
'message.phone.received',
'message.phone.sent',
@@ -1219,13 +1219,11 @@ export default Vue.extend({
id: null,
name: '',
timezone: '',
- is_active: true,
windows: [],
} as {
id: string | null
name: string
timezone: string
- is_active: boolean
windows: Array<{
day_of_week: number
start_time: string
@@ -1588,7 +1586,7 @@ export default Vue.extend({
this.loadingSendSchedules = true
this.$store
.dispatch('getSendSchedules')
- .then((sendSchedules: EntitiesSendSchedule[]) => {
+ .then((sendSchedules: EntitiesMessageSendSchedule[]) => {
this.sendSchedules = sendSchedules
})
.finally(() => {
@@ -1673,7 +1671,7 @@ export default Vue.extend({
return this.weekDays.find((x) => x.value == index)?.label ?? ''
},
- scheduleSummary(schedule: EntitiesSendSchedule) {
+ scheduleSummary(schedule: EntitiesMessageSendSchedule) {
return this.weekDays
.map((day) => {
const windows = (schedule.windows || []).filter(
@@ -1711,7 +1709,6 @@ export default Vue.extend({
id: null,
name: '',
timezone: this.defaultTimezone(),
- is_active: true,
windows: [
{ day_of_week: 1, start_time: '09:00', end_time: '17:00' },
{ day_of_week: 2, start_time: '09:00', end_time: '17:00' },
@@ -1723,16 +1720,12 @@ export default Vue.extend({
this.showScheduleEdit = true
},
- openEditSchedule(schedule: EntitiesSendSchedule) {
+ openEditSchedule(schedule: EntitiesMessageSendSchedule) {
this.resetErrors()
this.activeSchedule = {
id: schedule.id,
name: schedule.name,
timezone: schedule.timezone,
- is_active:
- typeof schedule.is_active !== 'undefined'
- ? schedule.is_active
- : Boolean((schedule as any).active),
windows: (schedule.windows || []).map((x) => ({
day_of_week: x.day_of_week,
start_time: this.minuteToClock(x.start_minute),
@@ -1806,7 +1799,6 @@ export default Vue.extend({
const payload = {
name: this.activeSchedule.name,
timezone: this.activeSchedule.timezone,
- is_active: this.activeSchedule.is_active,
windows: (this.activeSchedule.windows || []).map((window) => ({
day_of_week: window.day_of_week,
start_minute: this.clockToMinute(window.start_time),
diff --git a/web/store/index.ts b/web/store/index.ts
index bd3071e6..fc53c395 100644
--- a/web/store/index.ts
+++ b/web/store/index.ts
@@ -9,27 +9,27 @@ import { BillingUsage } from '~/models/billing'
import {
EntitiesDiscord,
EntitiesMessage,
+ EntitiesMessageSendSchedule,
EntitiesPhone,
EntitiesPhoneAPIKey,
- EntitiesSendSchedule,
EntitiesUser,
EntitiesWebhook,
RequestsDiscordStore,
RequestsDiscordUpdate,
- RequestsSendScheduleStore,
+ RequestsMessageSendScheduleStore,
RequestsUserNotificationUpdate,
RequestsUserPaymentInvoice,
RequestsWebhookStore,
RequestsWebhookUpdate,
ResponsesDiscordResponse,
ResponsesDiscordsResponse,
+ ResponsesMessageSendScheduleResponse,
+ ResponsesMessageSendSchedulesResponse,
ResponsesMessagesResponse,
ResponsesNoContent,
ResponsesOkString,
ResponsesPhoneAPIKeyResponse,
ResponsesPhoneAPIKeysResponse,
- ResponsesSendScheduleResponse,
- ResponsesSendSchedulesResponse,
ResponsesUnprocessableEntity,
ResponsesUserResponse,
ResponsesUserSubscriptionPaymentsResponse,
@@ -381,7 +381,7 @@ export const actions = {
missed_call_auto_reply: phone.missed_call_auto_reply,
max_send_attempts: parseInt(phone.max_send_attempts.toString()),
messages_per_minute: parseInt(phone.messages_per_minute.toString()),
- schedule_id: phone.schedule_id ?? null,
+ message_send_schedule_id: phone.message_send_schedule_id ?? null,
})
context.dispatch('addNotification', {
@@ -1109,34 +1109,45 @@ export const actions = {
},
getSendSchedules(context: ActionContext<State, State>) {
- return new Promise<Array<EntitiesSendSchedule>>((resolve, reject) => {
- axios
- .get<ResponsesSendSchedulesResponse>(`/v1/send-schedules`)
- .then((response: AxiosResponse<ResponsesSendSchedulesResponse>) => {
- resolve(response.data.data)
- })
- .catch(async (error: AxiosError) => {
- await context.dispatch('addNotification', {
- message:
- (error.response?.data as any)?.message ??
- 'Error while fetching send schedules',
- type: 'error',
+ return new Promise<Array<EntitiesMessageSendSchedule>>(
+ (resolve, reject) => {
+ axios
+ .get<ResponsesMessageSendSchedulesResponse>(`/v1/send-schedules`)
+ .then(
+ (
+ response: AxiosResponse<ResponsesMessageSendSchedulesResponse>,
+ ) => {
+ resolve(response.data.data)
+ },
+ )
+ .catch(async (error: AxiosError) => {
+ await context.dispatch('addNotification', {
+ message:
+ (error.response?.data as any)?.message ??
+ 'Error while fetching send schedules',
+ type: 'error',
+ })
+ reject(getErrorMessages(error))
})
- reject(getErrorMessages(error))
- })
- })
+ },
+ )
},
createSendSchedule(
context: ActionContext<State, State>,
- payload: RequestsSendScheduleStore,
+ payload: RequestsMessageSendScheduleStore,
) {
- return new Promise<EntitiesSendSchedule>((resolve, reject) => {
+ return new Promise<EntitiesMessageSendSchedule>((resolve, reject) => {
axios
- .post<ResponsesSendScheduleResponse>(`/v1/send-schedules`, payload)
- .then((response: AxiosResponse<ResponsesSendScheduleResponse>) => {
- resolve(response.data.data)
- })
+ .post<ResponsesMessageSendScheduleResponse>(
+ `/v1/send-schedules`,
+ payload,
+ )
+ .then(
+ (response: AxiosResponse<ResponsesMessageSendScheduleResponse>) => {
+ resolve(response.data.data)
+ },
+ )
.catch(async (error: AxiosError) => {
await context.dispatch('addNotification', {
message:
@@ -1151,17 +1162,19 @@ export const actions = {
updateSendSchedule(
context: ActionContext<State, State>,
- payload: RequestsSendScheduleStore & { id: string },
+ payload: RequestsMessageSendScheduleStore & { id: string },
) {
- return new Promise<EntitiesSendSchedule>((resolve, reject) => {
+ return new Promise<EntitiesMessageSendSchedule>((resolve, reject) => {
axios
- .put<ResponsesSendScheduleResponse>(
+ .put<ResponsesMessageSendScheduleResponse>(
`/v1/send-schedules/${payload.id}`,
payload,
)
- .then((response: AxiosResponse<ResponsesSendScheduleResponse>) => {
- resolve(response.data.data)
- })
+ .then(
+ (response: AxiosResponse<ResponsesMessageSendScheduleResponse>) => {
+ resolve(response.data.data)
+ },
+ )
.catch(async (error: AxiosError) => {
await context.dispatch('addNotification', {
message: