Created
October 21, 2022 15:20
-
-
Save Mr-Malomz/8d4ac89bc51282b79382033ca276ce0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package api | |
import ( | |
"github.com/twilio/twilio-go" | |
twilioApi "github.com/twilio/twilio-go/rest/verify/v2" | |
) | |
var client *twilio.RestClient = twilio.NewRestClientWithParams(twilio.ClientParams{ | |
Username: envACCOUNTSID(), | |
Password: envAUTHTOKEN(), | |
}) | |
func (app *Config) twilioSendOTP(phoneNumber string) (string, error) { | |
params := &twilioApi.CreateVerificationParams{} | |
params.SetTo(phoneNumber) | |
params.SetChannel("sms") | |
resp, err := client.VerifyV2.CreateVerification(envSERVICESID(), params) | |
if err != nil { | |
return "", err | |
} | |
return *resp.Sid, nil | |
} | |
func (app *Config) twilioVerifyOTP(phoneNumber string, code string) error { | |
params := &twilioApi.CreateVerificationCheckParams{} | |
params.SetTo(phoneNumber) | |
params.SetCode(code) | |
resp, err := client.VerifyV2.CreateVerificationCheck(envSERVICESID(), params) | |
if err != nil { | |
return err | |
} else if *resp.Status == "approved" { | |
return nil | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment