Skip to content

Instantly share code, notes, and snippets.

@Mr-Malomz
Created October 21, 2022 15:20
Show Gist options
  • Save Mr-Malomz/8d4ac89bc51282b79382033ca276ce0e to your computer and use it in GitHub Desktop.
Save Mr-Malomz/8d4ac89bc51282b79382033ca276ce0e to your computer and use it in GitHub Desktop.
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