-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessage_code_team.go
70 lines (60 loc) · 2.07 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package chat
import (
"context"
"github.com/pkg/errors"
chatpb "github.com/code-payments/code-protobuf-api/generated/go/chat/v1"
"github.com/code-payments/code-server/pkg/code/common"
code_data "github.com/code-payments/code-server/pkg/code/data"
"github.com/code-payments/code-server/pkg/code/data/chat"
"github.com/code-payments/code-server/pkg/code/data/intent"
"github.com/code-payments/code-server/pkg/code/localization"
)
// SendCodeTeamMessage sends a message to the Code Team chat.
func SendCodeTeamMessage(ctx context.Context, data code_data.Provider, receiver *common.Account, chatMessage *chatpb.ChatMessage) (bool, error) {
return SendChatMessage(
ctx,
data,
CodeTeamName,
chat.ChatTypeInternal,
true,
receiver,
chatMessage,
false,
)
}
// 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{
KeyOrText: 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)
}