forked from bots-go-framework/bots-fw
/
context.go
102 lines (78 loc) · 2.47 KB
/
context.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package bots
import (
"net/http"
"context"
"github.com/strongo/app"
"github.com/strongo/db"
"github.com/strongo/gamp"
)
// WebhookInlineQueryContext provides context for inline query (TODO: check & document)
type WebhookInlineQueryContext interface {
}
// GaQueuer queues messages for sending to Google Analytics
type GaQueuer interface { // TODO: can be unexported?
Queue(message gamp.Message) error
}
// GaContext provides context to Google Analytics
type GaContext interface {
GaQueuer
// Flush() error
GaCommon() gamp.Common
GaEvent(category, action string) *gamp.Event
GaEventWithLabel(category, action, label string) *gamp.Event
}
// WebhookContext provides context for current request from user to bot
type WebhookContext interface {
// TODO: Make interface smaller?
GA() GaContext
db.TransactionCoordinator
Environment() strongo.Environment
BotInputProvider
BotPlatform() BotPlatform
Request() *http.Request
//Init(w http.ResponseWriter, r *http.Request) error
Context() context.Context
SetContext(c context.Context)
ExecutionContext() strongo.ExecutionContext
BotAppContext() BotAppContext
BotContext() BotContext
MustBotChatID() string
GetBotCode() string
GetBotToken() string
GetBotSettings() BotSettings
ChatEntity() BotChat
IsInGroup() bool
CommandText(title, icon string) string
//Locale() strongo.ByLocale
SetLocale(code5 string) error
NewMessage(text string) MessageFromBot
NewMessageByCode(messageCode string, a ...interface{}) MessageFromBot
NewEditMessage(text string, format MessageFormat) (MessageFromBot, error)
//NewEditMessageKeyboard(kbMarkup tgbotapi.InlineKeyboardMarkup) MessageFromBot
UpdateLastProcessed(chatEntity BotChat) error
AppUserIntID() int64
AppUserStrID() string
GetAppUser() (BotAppUser, error)
//SaveAppUser(appUserID int64, appUserEntity BotAppUser) error
BotState
BotChatStore // TODO: Migrate to strongo/db
BotUserStore // TODO: Migrate to strongo/db
WebhookInput // TODO: Should be removed!!!
strongo.SingleLocaleTranslator
Responder() WebhookResponder
}
// BotState provides state of the bot (TODO: document how is used)
type BotState interface {
IsNewerThen(chatEntity BotChat) bool
}
// BotInputProvider provides an input from a specific bot interface (Telegram, FB Messenger, Viber, etc.)
type BotInputProvider interface {
Input() WebhookInput
}
// BotAPIUser provides info about current bot user
type BotAPIUser interface {
//IdAsString() string
//IdAsInt64() int64
FirstName() string
LastName() string
}