github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/sms_send/sms_send.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/grokify/mogo/config"
    10  	"github.com/grokify/mogo/fmt/fmtutil"
    11  	"github.com/jessevdk/go-flags"
    12  
    13  	rc "github.com/grokify/go-ringcentral-client/office/v1/client"
    14  	ru "github.com/grokify/go-ringcentral-client/office/v1/util"
    15  )
    16  
    17  type CliOptions struct {
    18  	EnvFile string `short:"e" long:"env" description:"Env filepath"`
    19  }
    20  
    21  // example: $ go run fax_send.go -to=+16505550100 -file=$GOPATH/src/github.com/grokify/go-ringcentral-client/office/v1/examples/fax_send/test_file.pdf
    22  func main() {
    23  	opts := CliOptions{}
    24  	_, err := flags.Parse(&opts)
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  	_, err = config.LoadDotEnv([]string{opts.EnvFile, os.Getenv("ENV_PATH"), "./.env"}, 1)
    29  	if err != nil {
    30  		log.Fatal(err)
    31  	}
    32  
    33  	apiClient, err := ru.NewApiClientPasswordEnv("RINGCENTRAL_")
    34  	if err != nil {
    35  		log.Fatal(err)
    36  	}
    37  
    38  	params := rc.CreateSmsMessage{
    39  		From: rc.MessageStoreCallerInfoRequest{
    40  			PhoneNumber: os.Getenv("RINGCENTRAL_DEMO_SMS_FROM")},
    41  		To: []rc.MessageStoreCallerInfoRequest{
    42  			{
    43  				PhoneNumber: os.Getenv("RINGCENTRAL_DEMO_SMS_TO")}},
    44  		Text: os.Getenv("RINGCENTRAL_DEMO_SMS_TEXT")}
    45  
    46  	fmtutil.PrintJSON(params)
    47  
    48  	info, resp, err := apiClient.MessagesApi.SendSMS(context.Background(), "~", "~", params)
    49  
    50  	if err != nil {
    51  		panic(err)
    52  	} else if resp.StatusCode > 299 {
    53  		panic(fmt.Errorf("API Status %v", resp.StatusCode))
    54  	}
    55  	fmtutil.PrintJSON(info)
    56  
    57  	fmt.Println("DONE")
    58  }