Created
September 27, 2021 10:23
-
-
Save karthikraobr/3500291b569f848a21cd95d5de5fb510 to your computer and use it in GitHub Desktop.
This file contains 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 main | |
import ( | |
"bufio" | |
"errors" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"github.com/twilio/twilio-go" | |
client "github.com/twilio/twilio-go/client" | |
openapi "github.com/twilio/twilio-go/rest/verify/v2" | |
) | |
const ( | |
SID = "" | |
SECRET = "" | |
VSID = "" | |
) | |
var twClient = twilio.NewRestClientWithParams(twilio.RestClientParams{ | |
Username: SID, | |
Password: SECRET, | |
}) | |
func main() { | |
// country := "DE" | |
channel := "sms" | |
to := "+49XXXXXXXXXXXXX" | |
locale := "en" | |
text := "you text is" | |
//rateLimit() | |
// svc1, _ := twClient.VerifyV2.FetchService(VSID) | |
// if svc1.Links != nil { | |
// val := *svc1.Links | |
// rr := val["rate_limits"] | |
// fmt.Print(rr) | |
// } | |
svc, err := twClient.VerifyV2.CreateVerification(VSID, &openapi.CreateVerificationParams{ | |
Channel: &channel, | |
To: &to, | |
Locale: &locale, | |
CustomMessage: &text, | |
RateLimits: &map[string]interface{}{ | |
"sms_rate_limit": to, | |
}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Print(*svc.Status) | |
reader := bufio.NewReader(os.Stdin) | |
fmt.Print("Enter text: ") | |
text, _ := reader.ReadString('\n') | |
fmt.Println(text) | |
text = strings.TrimSuffix(text, "\n") | |
payload := openapi.CreateVerificationCheckParams{ | |
To: &to, | |
Code: &text, | |
} | |
fmt.Println(*payload.To, *payload.Code) | |
check, err := twClient.VerifyV2.CreateVerificationCheck(VSID, &payload) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(*check.Valid) | |
fmt.Println(*check.Status) | |
fmt.Println(*svc.Status) | |
} | |
func rateLimit() { | |
rl, err := twClient.VerifyV2.CreateRateLimit(VSID, &openapi.CreateRateLimitParams{Description: toString("sms rate limit"), UniqueName: toString("sms_rate_limit")}) | |
if err != nil { | |
var twErr *client.TwilioRestError | |
if errors.As(err, &twErr) { | |
log.Fatal(twErr) | |
} | |
} | |
bucket, err := twClient.VerifyV2.CreateBucket(VSID, *rl.Sid, &openapi.CreateBucketParams{ | |
Interval: toInt(3600), | |
Max: toInt(3), | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Println(bucket.Url) | |
} | |
func toString(val string) *string { | |
return &val | |
} | |
func toInt(val int) *int { | |
return &val | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment