Skip to content

Commit

Permalink
twilio: add Voice Insights API
Browse files Browse the repository at this point in the history
Added all three [Twilio Voice Insights API](https://www.twilio.com/docs/voice/insights/api) resources:

- Summary
- Events
- Metrics

How to use it:

```
t.client.Insights.VoiceInsights(callSID).Metrics.GetPage(ctx, params)

t.client.Insights.VoiceInsights(callSID).Events.GetPage(ctx, params)

t.client.Insights.VoiceInsights(callSID).Summary.Get(ctx)
t.client.Insights.VoiceInsights(callSID).Summary.GetPartial(ctx)
```
  • Loading branch information
yeoji authored and kevinburke committed Aug 10, 2020
1 parent bc580f9 commit cb4dae5
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Andrey Mak <andrey.mak@yahoo.com>
Duncan Crawford <duncan@noughtsandones.co.uk>
Elijah Oyekunle <eloyekunle@gmail.com>
Fabrizio Moscon <mosconfabrizio@gmail.com>
Joey Lee <jq@yeoji.com>
Josh Hornby <hello@joshhornby.co.uk>
Kelmer Perez <kperez@wyzant.com>
Kevin Burke <kevin@burke.dev>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The API is unlikely to change, and currently covers these resources:
- Workflows
- Transcriptions
- Wireless
- Voice Insights
- Access Tokens for IPMessaging, Video and Programmable Voice SDK

### Error Parsing
Expand Down
35 changes: 35 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ var TaskRouterBaseUrl = "https://taskrouter.twilio.com"

const TaskRouterVersion = "v1"

// Voice Insights service
var InsightsBaseUrl = "https://insights.twilio.com"

const InsightsVersion = "v1"

type Client struct {
*rest.Client
Monitor *Client
Expand All @@ -78,6 +83,7 @@ type Client struct {
Verify *Client
Video *Client
TaskRouter *Client
Insights *Client

// FullPath takes a path part (e.g. "Messages") and
// returns the full API path, including the version (e.g.
Expand Down Expand Up @@ -134,6 +140,9 @@ type Client struct {

// NewTaskRouterClient initializes these services
Workspace func(sid string) *WorkspaceService

// NewInsightsClient initializes these services
VoiceInsights func(sid string) *VoiceInsightsService
}

const defaultTimeout = 30*time.Second + 500*time.Millisecond
Expand Down Expand Up @@ -269,6 +278,28 @@ func NewTaskRouterClient(accountSid string, authToken string, httpClient *http.C
return c
}

func NewInsightsClient(accountSid string, authToken string, httpClient *http.Client) *Client {
c := newNewClient(accountSid, authToken, InsightsBaseUrl, httpClient)
c.APIVersion = InsightsVersion
c.VoiceInsights = func(callSid string) *VoiceInsightsService {
return &VoiceInsightsService{
Summary: &CallSummaryService{
callSid: callSid,
client: c,
},
Metrics: &CallMetricsService{
callSid: callSid,
client: c,
},
Events: &CallEventsService{
callSid: callSid,
client: c,
},
}
}
return c
}

// NewPricingClient returns a new Client to use the pricing API
func NewPricingClient(accountSid string, authToken string, httpClient *http.Client) *Client {
c := newNewClient(accountSid, authToken, PricingBaseURL, httpClient)
Expand Down Expand Up @@ -345,6 +376,7 @@ func NewClient(accountSid string, authToken string, httpClient *http.Client) *Cl
c.Verify = NewVerifyClient(accountSid, authToken, httpClient)
c.Video = NewVideoClient(accountSid, authToken, httpClient)
c.TaskRouter = NewTaskRouterClient(accountSid, authToken, httpClient)
c.Insights = NewInsightsClient(accountSid, authToken, httpClient)

c.Accounts = &AccountService{client: c}
c.Applications = &ApplicationService{client: c}
Expand Down Expand Up @@ -434,6 +466,9 @@ func (c *Client) UseSecretKey(key string) {
if c.Wireless != nil {
c.Wireless.UseSecretKey(key)
}
if c.Insights != nil {
c.Insights.UseSecretKey(key)
}
}

// GetResource retrieves an instance resource with the given path part (e.g.
Expand Down
Loading

0 comments on commit cb4dae5

Please sign in to comment.