-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessage_code_team.go
51 lines (43 loc) · 1.54 KB
/
message_code_team.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package chat
import (
"github.com/pkg/errors"
chatpb "github.com/code-payments/code-protobuf-api/generated/go/chat/v1"
"github.com/code-payments/code-server/pkg/code/data/intent"
"github.com/code-payments/code-server/pkg/code/localization"
)
// ToWelcomeBonusMessage turns the intent record into a welcome bonus chat message
// to be inserted into the Code Team chat.
func ToWelcomeBonusMessage(intentRecord *intent.Record) (*chatpb.ChatMessage, error) {
return newIncentiveMessage(localization.ChatMessageWelcomeBonus, intentRecord)
}
// ToReferralBonusMessage turns the intent record into a referral bonus chat message
// to be inserted into the Code Team chat.
func ToReferralBonusMessage(intentRecord *intent.Record) (*chatpb.ChatMessage, error) {
return newIncentiveMessage(localization.ChatMessageReferralBonus, intentRecord)
}
func newIncentiveMessage(localizedTextKey string, intentRecord *intent.Record) (*chatpb.ChatMessage, error) {
exchangeData, ok := getExchangeDataFromIntent(intentRecord)
if !ok {
return nil, errors.New("exchange data not available")
}
content := []*chatpb.Content{
{
Type: &chatpb.Content_Localized{
Localized: &chatpb.LocalizedContent{
Key: localizedTextKey,
},
},
},
{
Type: &chatpb.Content_ExchangeData{
ExchangeData: &chatpb.ExchangeDataContent{
Verb: chatpb.ExchangeDataContent_RECEIVED,
ExchangeData: &chatpb.ExchangeDataContent_Exact{
Exact: exchangeData,
},
},
},
},
}
return newProtoChatMessage(intentRecord.IntentId, content, intentRecord.CreatedAt)
}