Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SMS testing with numbers that are not PhoneTypeCode 0 #251

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions src/users/src/users-service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,45 +370,42 @@ func UserVerifyAndUpdatePhone(w http.ResponseWriter, r *http.Request){
fmt.Println(res)
mobilePhoneCode := int(*res.NumberValidateResponse.PhoneTypeCode)
if (mobilePhoneCode != 0) {
var errMessage string = "The phone number provided is not a MOBILE phone number. The number is not capable of receiving SMS. Cannot create SMS endpoint for this number. Try entering a mobile phone number."
panic(errMessage)
http.Error(w, errMessage, 422)
return
} else {
var userAge string = strconv.Itoa(user.Age)
var userAttributes = make(map[string][]*string)
userAttributes["Username"] = []*string{&user.Username}
userAttributes["FirstName"] = []*string{&user.FirstName}
userAttributes["LastName"] = []*string{&user.LastName}
userAttributes["Gender"] = []*string{&user.Gender}
userAttributes["Age"] = []*string{&userAge}

endpointRequest := &pinpoint.EndpointRequest{
Address: &userDetails.PhoneNumber,
ChannelType: aws.String("SMS"),
OptOut: aws.String("ALL"),
Location: &pinpoint.EndpointLocation {
PostalCode: res.NumberValidateResponse.ZipCode,
City: res.NumberValidateResponse.City,
Country: res.NumberValidateResponse.CountryCodeIso2,
},
Demographic: &pinpoint.EndpointDemographic {
Timezone: res.NumberValidateResponse.Timezone,
},
User: &pinpoint.EndpointUser{
UserAttributes: userAttributes,
UserId: &userDetails.UserID,
},
}
var endpointId string = userDetails.PhoneNumber[1:]
updateEndpointInput := &pinpoint.UpdateEndpointInput{
ApplicationId: &pinpoint_app_id,
EndpointId: &endpointId,
EndpointRequest: endpointRequest,
}
CreateEndpointAndSendConfirmation(w, r, updateEndpointInput, userDetails.PhoneNumber)
}
var warnMessage string = "The phone number provided is not a MOBILE phone number (PhoneTypeCode=0). The number may not be capable of receiving SMS."
fmt.Println(warnMessage)
}
var userAge string = strconv.Itoa(user.Age)
var userAttributes = make(map[string][]*string)
userAttributes["Username"] = []*string{&user.Username}
userAttributes["FirstName"] = []*string{&user.FirstName}
userAttributes["LastName"] = []*string{&user.LastName}
userAttributes["Gender"] = []*string{&user.Gender}
userAttributes["Age"] = []*string{&userAge}

endpointRequest := &pinpoint.EndpointRequest{
Address: &userDetails.PhoneNumber,
ChannelType: aws.String("SMS"),
OptOut: aws.String("ALL"),
Location: &pinpoint.EndpointLocation {
PostalCode: res.NumberValidateResponse.ZipCode,
City: res.NumberValidateResponse.City,
Country: res.NumberValidateResponse.CountryCodeIso2,
},
Demographic: &pinpoint.EndpointDemographic {
Timezone: res.NumberValidateResponse.Timezone,
},
User: &pinpoint.EndpointUser{
UserAttributes: userAttributes,
UserId: &userDetails.UserID,
},
}
var endpointId string = userDetails.PhoneNumber[1:]
updateEndpointInput := &pinpoint.UpdateEndpointInput{
ApplicationId: &pinpoint_app_id,
EndpointId: &endpointId,
EndpointRequest: endpointRequest,
}
CreateEndpointAndSendConfirmation(w, r, updateEndpointInput, userDetails.PhoneNumber)
}
}
t := RepoUpdateUser(user)

Expand Down