@@ -2,6 +2,7 @@ package telegram
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"github.com/bots-go-framework/bots-api-telegram/tgbotapi"
7
8
"github.com/bots-go-framework/bots-fw-store/botsfwmodels"
@@ -124,43 +125,45 @@ func newTelegramWebhookContext(
124
125
args botsfw.CreateWebhookContextArgs ,
125
126
input TgWebhookInput ,
126
127
recordsFieldsSetter botsfw.BotRecordsFieldsSetter ,
127
- ) (* tgWebhookContext , error ) {
128
- twhc := & tgWebhookContext {
129
- tgInput : input ,
130
- }
128
+ ) (twhc * tgWebhookContext , err error ) {
129
+ twhc = & tgWebhookContext {tgInput : input }
130
+
131
131
chat := twhc .tgInput .TgUpdate ().Chat ()
132
132
133
- isInGroup := func () bool { // Checks if current chat is a group chat
133
+ getIsInGroup := func () ( isInGroup bool , err error ) { // Checks if current chat is a group chat
134
134
if chat != nil && chat .IsGroup () {
135
- return true
135
+ return true , nil
136
136
}
137
137
138
138
if callbackQuery := twhc .tgInput .TgUpdate ().CallbackQuery ; callbackQuery != nil && callbackQuery .ChatInstance != "" {
139
139
c := args .BotContext .BotHost .Context (args .HttpRequest )
140
140
var isGroupChat bool
141
- chatInstance , err := tgChatInstanceDal .GetTelegramChatInstanceByID (c , callbackQuery .ChatInstance )
142
- if err != nil {
141
+ if tgChatInstanceDal == nil {
142
+ err = errors .New ("tgChatInstanceDal is nil" )
143
+ return
144
+ }
145
+ var chatInstance botsfwtgmodels.TgChatInstanceData
146
+ if chatInstance , err = tgChatInstanceDal .GetTelegramChatInstanceByID (c , callbackQuery .ChatInstance ); err != nil {
143
147
if ! dal .IsNotFound (err ) {
144
148
logus .Errorf (c , "failed to get tg chat instance: %v" , err )
145
149
}
146
- return isGroupChat
150
+ return isGroupChat , err
147
151
} else if chatInstance != nil {
148
152
isGroupChat = chatInstance .GetTgChatID () < 0
149
153
}
150
- return isGroupChat
154
+ return isGroupChat , err
151
155
}
152
156
153
- return false
157
+ return false , err
154
158
}
155
159
156
- whcb , err : = botsfw .NewWebhookContextBase (
160
+ twhc . WebhookContextBase , err = botsfw .NewWebhookContextBase (
157
161
args ,
158
162
Platform ,
159
163
recordsFieldsSetter ,
160
- isInGroup ,
164
+ getIsInGroup ,
161
165
twhc .getLocalAndChatIDByChatInstance ,
162
166
)
163
- twhc .WebhookContextBase = whcb
164
167
return twhc , err
165
168
}
166
169
0 commit comments