Skip to content

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

fix billing

Acho Arnold7467eece2f0a
diff --git a/android/app/src/main/java/com/httpsms/MainActivity.kt b/android/app/src/main/java/com/httpsms/MainActivity.kt
index 8a8665c4..cc827234 100644
--- a/android/app/src/main/java/com/httpsms/MainActivity.kt
+++ b/android/app/src/main/java/com/httpsms/MainActivity.kt
@@ -70,6 +70,7 @@ class MainActivity : AppCompatActivity() {
super.onResume()
Timber.d( "on activity resume")
redirectToLogin()
+ setOwner(getPhoneNumber(this))
refreshToken(this)
setLastHeartbeatTimestamp(this)
}
diff --git a/android/app/src/main/java/com/httpsms/Settings.kt b/android/app/src/main/java/com/httpsms/Settings.kt
index a9fcc1fe..fee8a754 100644
--- a/android/app/src/main/java/com/httpsms/Settings.kt
+++ b/android/app/src/main/java/com/httpsms/Settings.kt
@@ -6,7 +6,7 @@ import timber.log.Timber
import java.net.URI
object Settings {
- private const val DEFAULT_PHONE_NUMBER = "66836863" // NOT_FOUND :)
+ private const val DEFAULT_PHONE_NUMBER = "NOT_FOUND"
private const val SETTINGS_OWNER = "SETTINGS_OWNER"
private const val SETTINGS_ACTIVE = "SETTINGS_ACTIVE_STATUS"
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index 78786860..6a6e8cc7 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -2,6 +2,7 @@ package di
import (
"context"
+ "crypto/tls"
"fmt"
"net/http"
"os"
@@ -258,6 +259,10 @@ func (container *Container) Cache() cache.Cache {
if err != nil {
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot parse redis url [%s]", os.Getenv("REDIS_URL"))))
}
+ opt.TLSConfig = &tls.Config{
+ MinVersion: tls.VersionTLS12,
+ }
+
return cache.NewRedisCache(container.Tracer(), redis.NewClient(opt))
}
diff --git a/api/pkg/emails/hermes_user_email_factory.go b/api/pkg/emails/hermes_user_email_factory.go
index 9197df05..f8971e81 100644
--- a/api/pkg/emails/hermes_user_email_factory.go
+++ b/api/pkg/emails/hermes_user_email_factory.go
@@ -19,16 +19,15 @@ func (factory *hermesUserEmailFactory) UsageLimitExceeded(user *entities.User) (
email := hermes.Email{
Body: hermes.Body{
Intros: []string{
- fmt.Sprintf("You have exceeded your limit of [%d] messages on your [%s] plan.", user.SubscriptionName.Limit(), user.SubscriptionName),
- fmt.Sprintf("Upgrade your plan to send more messages on https://httpsms.com/billing"),
+ fmt.Sprintf("You have exceeded your limit of %d messages on your %s plan.", user.SubscriptionName.Limit(), user.SubscriptionName),
},
Actions: []hermes.Action{
{
- Instructions: "Click the button below to upgrade your plan",
+ Instructions: "Click the button below to upgrade your plan and continue sending more messages",
Button: hermes.Button{
Color: "#329ef4",
TextColor: "#FFFFFF",
- Text: "UPGRADE PLAN",
+ Text: "Upgrade your httpSMS plan",
Link: "https://httpsms.com/billing",
},
},
@@ -65,12 +64,12 @@ func (factory *hermesUserEmailFactory) UsageLimitAlert(user *entities.User, usag
email := hermes.Email{
Body: hermes.Body{
Intros: []string{
- fmt.Sprintf("This is a friendly notification that you have exceeded %d of your monthly SMS limit on the %s plan.", percent, user.SubscriptionName),
- fmt.Sprintf("You have sent %d messages and received %d messages. Upgrade your plan to send more messages on https://httpsms.com/billing", usage.SentMessages, usage.ReceivedMessages),
+ fmt.Sprintf("This is a friendly notification that you have exceeded %d%% of your monthly SMS limit on the %s plan.", percent, user.SubscriptionName),
+ fmt.Sprintf("You have sent %d messages and received %d messages using httpSMS this month.", usage.SentMessages, usage.ReceivedMessages),
},
Actions: []hermes.Action{
{
- Instructions: "Click the button below to upgrade your plan",
+ Instructions: "Click the button below to upgrade your plan so you can continue without any disruptions",
Button: hermes.Button{
Color: "#329ef4",
TextColor: "#FFFFFF",
diff --git a/web/layouts/default.vue b/web/layouts/default.vue
index f8e73db0..0c00a32e 100644
--- a/web/layouts/default.vue
+++ b/web/layouts/default.vue
@@ -37,10 +37,7 @@ export default class DefaultLayout extends Vue {
}
mounted() {
- // if (this.$route.name !== 'index') {
- // this.$store.dispatch('setNextRoute', this.$route.path)
- // this.$router.push({ name: 'index' })
- // }
+ this.startPoller()
}
beforeDestroy(): void {
@@ -57,7 +54,7 @@ export default class DefaultLayout extends Vue {
if (this.$store.getters.getAuthUser && this.$store.getters.getOwner) {
promises.push(
this.$store.dispatch('loadThreads'),
- this.$store.dispatch('getHeartbeat')
+ this.$store.dispatch('getHeartbeat'),
)
}
@@ -69,8 +66,8 @@ export default class DefaultLayout extends Vue {
promises.push(
this.$store.dispatch(
'loadThreadMessages',
- this.$store.getters.getThread.id
- )
+ this.$store.getters.getThread.id,
+ ),
)
}
await Promise.all(promises)
diff --git a/web/store/index.ts b/web/store/index.ts
index 0bf0cef4..25587f63 100644
--- a/web/store/index.ts
+++ b/web/store/index.ts
@@ -360,7 +360,7 @@ export const actions = {
fcm_token: phone.fcm_token,
phone_number: phone.phone_number,
message_expiration_seconds: parseInt(
- phone.message_expiration_seconds.toString()
+ phone.message_expiration_seconds.toString(),
),
max_send_attempts: parseInt(phone.max_send_attempts.toString()),
messages_per_minute: parseInt(phone.messages_per_minute.toString()),
@@ -380,7 +380,7 @@ export const actions = {
async handleAxiosError(
context: ActionContext<State, State>,
- error: AxiosError
+ error: AxiosError,
) {
const errorMessage =
error.response?.data?.data[Object.keys(error.response?.data?.data)[0]][0]
@@ -415,9 +415,22 @@ export const actions = {
async sendMessage(
context: ActionContext<State, State>,
- request: SendMessageRequest
+ request: SendMessageRequest,
) {
- await axios.post('/v1/messages/send', request)
+ try {
+ const response = await axios.post('/v1/messages/send', request)
+ await context.dispatch('addNotification', {
+ message: response.data.message,
+ type: 'success',
+ })
+ } catch (e) {
+ await context.dispatch('addNotification', {
+ message:
+ (e as AxiosError).response?.data?.message ??
+ 'Error while sending message',
+ type: 'error',
+ })
+ }
await Promise.all([
context.dispatch('loadThreadMessages', context.getters.getThread.id),
context.dispatch('loadThreads'),
@@ -430,7 +443,7 @@ export const actions = {
addNotification(
context: ActionContext<State, State>,
- request: NotificationRequest
+ request: NotificationRequest,
) {
context.commit('setNotification', request)
},
@@ -445,7 +458,7 @@ export const actions = {
async loadThreadMessages(
context: ActionContext<State, State>,
- threadId: string | null
+ threadId: string | null,
) {
await context.commit('setThreadId', threadId)
const response = await axios.get('/v1/messages', {
@@ -460,7 +473,7 @@ export const actions = {
async setAuthUser(
context: ActionContext<State, State>,
- user: AuthUser | null | undefined
+ user: AuthUser | null | undefined,
) {
const userChanged = user?.id !== context.getters.getAuthUser?.id
@@ -477,7 +490,7 @@ export const actions = {
])
const phone = context.getters.getPhones.find(
- (x: Phone) => x.id === context.getters.getUser.active_phone_id
+ (x: Phone) => x.id === context.getters.getUser.active_phone_id,
)
if (phone) {
await context.dispatch('setOwner', phone.phone_number)
@@ -487,7 +500,7 @@ export const actions = {
async onAuthStateChanged(
context: ActionContext<State, State>,
// @ts-ignore
- { authUser }
+ { authUser },
) {
if (authUser == null) {
context.commit('setAuthUser', null)
@@ -520,7 +533,7 @@ export const actions = {
async updateThread(
context: ActionContext<State, State>,
- payload: { threadId: string; isArchived: boolean }
+ payload: { threadId: string; isArchived: boolean },
) {
await axios.put(`/v1/message-threads/${payload.threadId}`, {
is_archived: payload.isArchived,
@@ -573,7 +586,7 @@ export const actions = {
createWebhook(
context: ActionContext<State, State>,
- payload: RequestsWebhookStore
+ payload: RequestsWebhookStore,
) {
return new Promise<EntitiesWebhook>((resolve, reject) => {
axios
@@ -621,7 +634,7 @@ export const actions = {
updateWebhook(
context: ActionContext<State, State>,
- payload: RequestsWebhookUpdate & { id: string }
+ payload: RequestsWebhookUpdate & { id: string },
) {
return new Promise<EntitiesWebhook>((resolve, reject) => {
axios