Skip to content

Commit

Permalink
chore: update sms copy (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: Dumbledore <mathenge@healthcloud.co.ke>
  • Loading branch information
ageeknamedslickback committed Aug 12, 2021
1 parent f8491ba commit 1b0cbc4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
6 changes: 3 additions & 3 deletions launch/send_sms/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Wings(enum.Enum):

MESSAGE_A = {
"message": (
"Did you know you can now link your {} medical cover "
"on the Be.Well App and view your benefits? "
"To get started, Download Now {}. "
"You can now have FULL access to your's and your family's "
"{} virtual medical wellness cards here! "
"Download Be.Well to gain access {}. "
"For more information, call 0790 360 360. "
"To opt-out dial *384*600# Be.Well by Slade360"
),
Expand Down
65 changes: 53 additions & 12 deletions pkg/engagement/infrastructure/services/crm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crm
import (
"context"
"fmt"
"log"

"github.com/savannahghi/engagement/pkg/engagement/application/common/helpers"
"github.com/savannahghi/engagement/pkg/engagement/infrastructure/services/mail"
Expand All @@ -16,8 +17,15 @@ var tracer = otel.Tracer("github.com/savannahghi/engagement/pkg/engagement/useca
// ServiceCrm represents commontools crm lib usecases extension
type ServiceCrm interface {
IsOptedOut(ctx context.Context, phoneNumber string) (bool, error)
CollectEmails(ctx context.Context, email string, phonenumber string) (*hubspotDomain.CRMContact, error)
BeWellAware(ctx context.Context, email string) (*hubspotDomain.CRMContact, error)
CollectEmails(
ctx context.Context,
email string,
phonenumber string,
) (*hubspotDomain.CRMContact, error)
BeWellAware(
ctx context.Context,
email string,
) (*hubspotDomain.CRMContact, error)
}

// Hubspot interacts with `HubSpot` CRM usecases
Expand All @@ -27,37 +35,58 @@ type Hubspot struct {
}

// NewCrmService inits a new crm instance
func NewCrmService(hubSpotUsecases hubspotUsecases.HubSpotUsecases, mail mail.ServiceMail) *Hubspot {
func NewCrmService(
hubSpotUsecases hubspotUsecases.HubSpotUsecases,
mail mail.ServiceMail,
) *Hubspot {
return &Hubspot{
hubSpotUsecases: hubSpotUsecases,
mail: mail,
}
}

// IsOptedOut checks if a given phone number is opted out
func (h *Hubspot) IsOptedOut(ctx context.Context, phoneNumber string) (bool, error) {
func (h *Hubspot) IsOptedOut(
ctx context.Context,
phoneNumber string,
) (bool, error) {
return h.hubSpotUsecases.IsOptedOut(ctx, phoneNumber)
}

// CollectEmails receives an email and update the email of the found record in our firestore and hubspot CRM
func (h *Hubspot) CollectEmails(ctx context.Context, email string, phonenumber string) (*hubspotDomain.CRMContact, error) {
func (h *Hubspot) CollectEmails(
ctx context.Context,
email string,
phonenumber string,
) (*hubspotDomain.CRMContact, error) {
ctx, span := tracer.Start(ctx, "CollectEmails")
defer span.End()

contact, err := h.hubSpotUsecases.GetContactByPhone(ctx, phonenumber)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("failed to get contact with phone number %s: %w", phonenumber, err)
return nil, fmt.Errorf(
"failed to get contact with phone number %s: %w",
phonenumber,
err,
)
}
if contact == nil {
return nil, fmt.Errorf("contact with phonenumber %s not found", phonenumber)
return nil, fmt.Errorf(
"contact with phonenumber %s not found",
phonenumber,
)
}
contact.Properties.Email = email

updatedContact, err := h.hubSpotUsecases.UpdateHubSpotContact(ctx, contact)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("failed to update contact with phone number %s: %w", phonenumber, err)
return nil, fmt.Errorf(
"failed to update contact with phone number %s: %w",
phonenumber,
err,
)
}

name := "Kevin From Be.Well"
Expand All @@ -71,21 +100,29 @@ func (h *Hubspot) CollectEmails(ctx context.Context, email string, phonenumber s
email,
)
if err != nil {
return contact, fmt.Errorf("failed to send welcome email to %s: %w", email, err)
// todo: restore one mailgun is back
log.Printf("failed to send welcome email to %s: %v", email, err)
}

return updatedContact, nil
}

//BeWellAware toggles the user identified by the provided email as bewell-aware
func (h *Hubspot) BeWellAware(ctx context.Context, email string) (*hubspotDomain.CRMContact, error) {
func (h *Hubspot) BeWellAware(
ctx context.Context,
email string,
) (*hubspotDomain.CRMContact, error) {
ctx, span := tracer.Start(ctx, "BeWellAware")
defer span.End()

contact, err := h.hubSpotUsecases.GetContactByEmail(ctx, email)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("failed to get contact with email %s: %w", email, err)
return nil, fmt.Errorf(
"failed to get contact with email %s: %w",
email,
err,
)
}
if contact == nil {
return nil, fmt.Errorf("contact with email %s not found", email)
Expand All @@ -95,7 +132,11 @@ func (h *Hubspot) BeWellAware(ctx context.Context, email string) (*hubspotDomain
updatedContact, err := h.hubSpotUsecases.UpdateHubSpotContact(ctx, contact)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("failed to update contact with email %s: %w", email, err)
return nil, fmt.Errorf(
"failed to update contact with email %s: %w",
email,
err,
)
}
return updatedContact, nil
}

0 comments on commit 1b0cbc4

Please sign in to comment.