File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ type ChatBaseData struct {
24
24
BotBaseData
25
25
chatState
26
26
chatSettings
27
+ chatVars
27
28
28
29
// AppUserIntIDs is kept for legacy reasons
29
30
// Deprecated: replace with `AppUserIDs []string`
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ type BotChatData interface {
86
86
// PushStepToAwaitingReplyTo pushes step to awaiting reply to
87
87
PushStepToAwaitingReplyTo (code string )
88
88
//GetGaClientID() string
89
+
90
+ SetVar (key string , value string )
91
+ GetVar (key string ) string
92
+ DelVar (key string )
93
+ HasChangedVars () bool
89
94
}
90
95
91
96
// NewChatID create a new bot chat ID, returns string
Original file line number Diff line number Diff line change
1
+ package botsfwmodels
2
+
3
+ import (
4
+ "github.com/strongo/slice"
5
+ "slices"
6
+ )
7
+
8
+ type chatVars struct {
9
+ Vars map [string ]string `dalgo:"vars,omitempty" firestore:"vars,omitempty"`
10
+ changed []string
11
+ deleted []string
12
+ }
13
+
14
+ // GetVar returns a chat variable
15
+ func (v * chatVars ) GetVar (key string ) string {
16
+ if v .Vars == nil {
17
+ return ""
18
+ }
19
+ return v .Vars [key ]
20
+ }
21
+
22
+ // SetVar sets a chat variable
23
+ func (v * chatVars ) SetVar (key , value string ) {
24
+ if v .Vars == nil {
25
+ v .Vars = make (map [string ]string )
26
+ } else if v .Vars [key ] == value {
27
+ return
28
+ }
29
+ v .Vars [key ] = value
30
+ slice .RemoveInPlaceByValue (v .deleted , key )
31
+ if ! slices .Contains (v .changed , key ) {
32
+ v .changed = append (v .changed , key )
33
+ }
34
+ }
35
+
36
+ // DelVar deletes a chat variable
37
+ func (v * chatVars ) DelVar (key string ) {
38
+ if v .Vars == nil {
39
+ return
40
+ }
41
+ if _ , ok := v .Vars [key ]; ! ok {
42
+ return
43
+ }
44
+ delete (v .Vars , key )
45
+ v .changed = slice .RemoveInPlaceByValue (v .changed , key )
46
+ if ! slices .Contains (v .deleted , key ) {
47
+ v .deleted = append (v .deleted , key )
48
+ }
49
+ }
50
+
51
+ // HasChangedVars returns true if vars have been changed
52
+ func (v * chatVars ) HasChangedVars () bool {
53
+ return len (v .changed ) > 0 || len (v .deleted ) > 0
54
+ }
Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ module github.com/bots-go-framework/bots-fw-store
3
3
go 1.22
4
4
5
5
require github.com/strongo/validation v0.0.7
6
+
7
+ require github.com/strongo/slice v0.3.1 // indirect
Original file line number Diff line number Diff line change
1
+ github.com/strongo/slice v0.3.1 h1:VWkyYBgcVJn6Hs7wYhL9Vxwgb7V3zQAUFTBV9wo5lc4 =
2
+ github.com/strongo/slice v0.3.1 /go.mod h1:B5ODKCkl0rp2oiG0UBqkN1cCOrSCU2cUuhqCM1sC8r4 =
1
3
github.com/strongo/validation v0.0.7 h1:gs6YkwPsYtVsepQaQOB+ZF+T0Gu5+nk4ZMND8F85e+U =
2
4
github.com/strongo/validation v0.0.7 /go.mod h1:YUwoPEItLJd/Bc9X1OCUm03ofhvm3kwZvuihU7/jz58 =
You can’t perform that action at this time.
0 commit comments