Skip to content

Commit

Permalink
Addressing PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Jul 4, 2024
1 parent 16f6dd7 commit a017f80
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
5 changes: 0 additions & 5 deletions server/api_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ func (p *Plugin) handleSince(c *gin.Context) {
"user_actual_id": user.Id,
"since": data.Since,
"type": promptPreset,
"feature": map[string]any{
"name": "AI",
"is_free": false,
"skus": []string{"enterprise"},
},
})

prompt, err := p.prompts.ChatCompletion(promptPreset, context, p.getDefaultToolsStore(context.IsDMWithBot()))
Expand Down
10 changes: 0 additions & 10 deletions server/api_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ func (p *Plugin) handleSummarize(c *gin.Context) {
"channel_id": channel.Id,
"post_id": post.Id,
"user_actual_id": user.Id,
"feature": map[string]any{
"name": "AI",
"is_free": false,
"skus": []string{"enterprise"},
},
})

createdPost, err := p.startNewSummaryThread(bot, post.Id, p.MakeConversationContext(bot, user, channel, nil))
Expand Down Expand Up @@ -213,11 +208,6 @@ func (p *Plugin) handleSummarizeTranscription(c *gin.Context) {
"channel_id": channel.Id,
"post_id": post.Id,
"user_actual_id": user.Id,
"feature": map[string]any{
"name": "AI",
"is_free": false,
"skus": []string{"enterprise"},
},
})

createdPost, err := p.newCallTranscriptionSummaryThread(bot, user, post, channel)
Expand Down
41 changes: 36 additions & 5 deletions server/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/gin-gonic/gin"
"github.com/mattermost/mattermost-plugin-ai/server/telemetry"
"github.com/mattermost/mattermost/server/public/model"
"github.com/rudderlabs/analytics-go"
)

const (
Expand All @@ -28,6 +30,20 @@ var (
}
telemetryClientTypesMap map[string]struct{}
telemetryClientEventsMap map[string]struct{}

enterpriseSKUs = []string{model.LicenseShortSkuEnterprise}
// currently unused
// professionalSKUs = []string{model.LicenseShortSkuProfessional, model.LicenseShortSkuEnterprise}

// We only need to map events that require a SKU (i.e., licensed features). Anything available on unlicensed
// servers will map to null as expected.
eventToSkusMap = map[string][]string{
evUserStartedConversation: enterpriseSKUs,
evContextualInterrogation: enterpriseSKUs,
evSummarizeUnreadMessages: enterpriseSKUs,
evSummarizeThread: enterpriseSKUs,
evSummarizeTranscription: enterpriseSKUs,
}
)

func init() {
Expand All @@ -42,10 +58,15 @@ func init() {
}

type trackEventRequest struct {
Event string `json:"event"`
ClientType string `json:"clientType"`
Source string `json:"source"`
Props map[string]interface{} `json:"props"`
Event string `json:"event"`
ClientType string `json:"clientType"`
Source string `json:"source"`
Props map[string]any `json:"props"`
}

type eventFeature struct {
Name string `json:"name"`
Skus []string `json:"skus"`
}

func (p *Plugin) track(ev string, props map[string]interface{}) {
Expand All @@ -54,7 +75,17 @@ func (p *Plugin) track(ev string, props map[string]interface{}) {
if p.telemetry == nil {
return
}
if err := p.telemetry.Track(ev, props); err != nil {

ctx := &analytics.Context{
Extra: map[string]any{
"feature": eventFeature{
Name: "Copilot",
Skus: eventToSkusMap[ev],
},
},
}

if err := p.telemetry.Track(ev, props, ctx); err != nil {
p.API.LogError(err.Error())
}
}
Expand Down
7 changes: 4 additions & 3 deletions server/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ClientConfig struct {
WriteKey string
DataplaneURL string
DiagnosticID string
DefaultProps map[string]interface{}
DefaultProps map[string]any
}

func (c *ClientConfig) isValid() error {
Expand Down Expand Up @@ -48,9 +48,9 @@ func NewClient(config ClientConfig) (*Client, error) {
}, nil
}

func (c *Client) Track(event string, props map[string]interface{}) error {
func (c *Client) Track(event string, props map[string]interface{}, ctx *analytics.Context) error {
if props == nil {
props = map[string]interface{}{}
props = map[string]any{}
}

for k, v := range c.config.DefaultProps {
Expand All @@ -61,6 +61,7 @@ func (c *Client) Track(event string, props map[string]interface{}) error {
Event: event,
UserId: c.config.DiagnosticID,
Properties: props,
Context: ctx,
}); err != nil {
return fmt.Errorf("telemetry: failed to track event: %w", err)
}
Expand Down

0 comments on commit a017f80

Please sign in to comment.