Skip to content

Commit

Permalink
Handle SMS opt-in data (#68)
Browse files Browse the repository at this point in the history
* Handle SMS opt-in data

* chore: Updated coverage badge.

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
harveysanders and actions-user authored Jul 20, 2023
1 parent a7cdd09 commit 5015bfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Session Sign Up Service

![Coverage](https://img.shields.io/badge/Coverage-55.2%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-54.7%25-yellow)

When someone signs up for an Info Session on [operationspark.org](https://operationspark.org),
this service runs a series of tasks:
Expand Down
22 changes: 12 additions & 10 deletions signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ type (
Email string `json:"email" schema:"email"`
GooglePlace greenlight.GooglePlace `json:"googlePlace" schema:"googlePlace"`
// Session's set location type. One of "IN_PERSON" | "VIRTUAL" | "IN_PERSON". If the session's location type is "HYBRID", a student can attend "IN_PERSON" or "VIRTUAL"ly.
LocationType string `json:"locationType" schema:"locationType"`
JoinCode string `json:"joinCode,omitempty"`
NameFirst string `json:"nameFirst" schema:"nameFirst"`
NameLast string `json:"nameLast" schema:"nameLast"`
ProgramID string `json:"programId" schema:"programId"`
Referrer string `json:"referrer" schema:"referrer"`
ReferrerResponse string `json:"referrerResponse" schema:"referrerResponse"`
SessionID string `json:"sessionId" schema:"sessionId"`
StartDateTime time.Time `json:"startDateTime,omitempty" schema:"startDateTime"`
Token string `json:"token" schema:"token"`
LocationType string `json:"locationType" schema:"locationType"`
JoinCode string `json:"joinCode,omitempty"`
NameFirst string `json:"nameFirst" schema:"nameFirst"`
NameLast string `json:"nameLast" schema:"nameLast"`
ProgramID string `json:"programId" schema:"programId"`
Referrer string `json:"referrer" schema:"referrer"`
ReferrerResponse string `json:"referrerResponse" schema:"referrerResponse"`
SessionID string `json:"sessionId" schema:"sessionId"`
// If the user has opted-in to receiving text messages.
SMSOptIn bool `json:"smsOptIn"`
StartDateTime time.Time `json:"startDateTime,omitempty" schema:"startDateTime"`
Token string `json:"token" schema:"token"`
// State or country where the person resides.
UserLocation string `json:"userLocation" schema:"userLocation"`
zoomMeetingID int64
Expand Down
15 changes: 15 additions & 0 deletions twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func NewTwilioService(o twilioServiceOptions) *smsService {
//
// Note: Twilio has a free Link Shortening service, but it is only available with the Messaging API, not Conversations.
func (t *smsService) run(ctx context.Context, su Signup) error {
if !su.SMSOptIn {
fmt.Printf("User opted-out from SMS messages: %s\n", su.String())
return nil
}

toNum := t.FormatCell(su.Cell)
convoName := fmt.Sprintf("%s %s", su.NameFirst, su.NameLast[0:1])
convoId := ""
Expand All @@ -122,6 +127,11 @@ func (t *smsService) run(ctx context.Context, su Signup) error {
convoId = *existing[0].ConversationSid
}

// Send Opt-in confirmation
if err := t.optInConfirmation(ctx, toNum); err != nil {
return fmt.Errorf("optInConfirmation: %w", err)
}

// create user-specific info session details URL
msgngURL, err := su.shortMessagingURL()
if err != nil {
Expand Down Expand Up @@ -247,6 +257,11 @@ func (t *smsService) sendConvoWebhook(ctx context.Context, convoID string) error
return nil
}

func (t *smsService) optInConfirmation(ctx context.Context, toNum string) error {
msg := "You've opted in for texts from Operation Spark for upcoming sessions. You can text us here if you have further questions. Message and data rates may apply. Reply STOP to unsubscribe."
return t.Send(ctx, toNum, msg)
}

// Send sends an SMS message to the given toNum and returns an error.
func (t *smsService) Send(ctx context.Context, toNum string, msg string) error {
// TODO: Maybe consolidate this code with some of the run() code
Expand Down

0 comments on commit 5015bfa

Please sign in to comment.