github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/thread_all/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  
     8  	"github.com/antihax/optional"
     9  	"github.com/jessevdk/go-flags"
    10  
    11  	engagedigital "github.com/grokify/go-ringcentral-client/engagedigital/v1/client"
    12  	ex "github.com/grokify/go-ringcentral-client/engagedigital/v1/examples"
    13  	utils "github.com/grokify/go-ringcentral-client/engagedigital/v1/util"
    14  )
    15  
    16  type options struct {
    17  	Site   string `short:"s" long:"site" description:"A site" required:"true"`
    18  	Token  string `short:"t" long:"token" description:"A token" required:"true"`
    19  	Action string `short:"a" long:"action" description:"Action" required:"true"`
    20  	Id     string `short:"i" long:"id" description:"An object id" required:"false"`
    21  	Object string `short:"o" long:"object" description:"An object" required:"false"`
    22  }
    23  
    24  func main() {
    25  	opts := options{}
    26  	_, err := flags.Parse(&opts)
    27  	if err != nil {
    28  		log.Fatal(err)
    29  	}
    30  
    31  	client := utils.NewApiClient(opts.Site, opts.Token)
    32  
    33  	switch opts.Action {
    34  	case "read":
    35  		if len(opts.Id) > 0 {
    36  			ex.HandleApiResponse(client.ThreadsApi.GetThread(context.Background(), opts.Id))
    37  		} else {
    38  			ex.HandleApiResponse(client.ThreadsApi.GetAllThreads(context.Background(), nil))
    39  		}
    40  	case "categorize":
    41  		if len(opts.Id) > 0 {
    42  			apiOpts := &engagedigital.CategorizeThreadOpts{
    43  				ThreadCategoryIds: optional.NewInterface([]string{"5c8bf22b14bf8a84c44c774c"})}
    44  			ex.HandleApiResponse(client.ThreadsApi.CategorizeThread(
    45  				context.Background(), opts.Id, apiOpts))
    46  		} else {
    47  			log.Fatal("E_CATEGORIZE_NO_THREAD_ID")
    48  		}
    49  	case "archive":
    50  		if len(opts.Id) > 0 {
    51  			ex.HandleApiResponse(client.ThreadsApi.ArchiveThread(context.Background(), opts.Id))
    52  		} else {
    53  			log.Fatal("E_ARCHIVE_NO_THREAD_ID")
    54  		}
    55  	case "close":
    56  		if len(opts.Id) > 0 {
    57  			ex.HandleApiResponse(client.ThreadsApi.CloseThread(context.Background(), opts.Id))
    58  		} else {
    59  			log.Fatal("E_CLOSE_NO_THREAD_ID")
    60  		}
    61  	case "open":
    62  		if len(opts.Id) > 0 {
    63  			ex.HandleApiResponse(client.ThreadsApi.OpenThread(context.Background(), opts.Id))
    64  		} else {
    65  			log.Fatal("E_OPEN_NO_THREAD_ID")
    66  		}
    67  	default:
    68  		log.Fatal(fmt.Sprintf("E_BAD_ACTION [%s]", opts.Action))
    69  	}
    70  
    71  	fmt.Println("DONE")
    72  }