Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
trakhimenok committed Apr 3, 2023
1 parent df74868 commit b7b9961
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 26 deletions.
9 changes: 0 additions & 9 deletions botsfw/bot_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package botsfw
import (
"time"

"context"
"github.com/satori/go.uuid"
"github.com/strongo/app/user"
)
Expand Down Expand Up @@ -46,14 +45,6 @@ type BotChat interface {
GetGaClientID() uuid.UUID
}

// BotChatStore is interface for DAL to store bot chat data
type BotChatStore interface {
GetBotChatEntityByID(c context.Context, botID, botChatID string) (BotChat, error)
SaveBotChat(c context.Context, botID, botChatID string, chatEntity BotChat) error
NewBotChatEntity(c context.Context, botID string, botChat WebhookChat, appUserID int64, botUserID string, isAccessGranted bool) BotChat
Close(c context.Context) error // TODO: Was io.Closer, should it?
}

// NewChatID create a new bot chat ID, returns string
func NewChatID(botID, botChatID string) string {
return botID + ":" + botChatID
Expand Down
11 changes: 11 additions & 0 deletions botsfw/bot_chat_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package botsfw

import "context"

// BotChatStore is interface for DAL to store bot chat data
type BotChatStore interface {
GetBotChatEntityByID(c context.Context, botID, botChatID string) (BotChat, error)
SaveBotChat(c context.Context, botID, botChatID string, chatEntity BotChat) error
NewBotChatEntity(c context.Context, botID string, botChat WebhookChat, appUserID, botUserID string, isAccessGranted bool) BotChat
Close(c context.Context) error // TODO: Was io.Closer, should it?
}
16 changes: 5 additions & 11 deletions botsfw/bot_user.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package botsfw

import (
"context"
"github.com/strongo/app/user"
)

// BotUser interface provides information about bot user
type BotUser interface {
GetAppUserIntID() int64
// GetAppUserIntID returns app user ID
// Deprecated: use GetAppUserStrID instead
GetAppUserIntID() int64 // TODO: decommission?
GetAppUserStrID() string
IsAccessGranted() bool
SetAccessGranted(value bool) bool
SetAppUserIntID(appUserID int64)
user.UpdatedTimeSetter
}

// BotUserStore provider to store information about bot user
type BotUserStore interface {
GetBotUserByID(c context.Context, botUserID interface{}) (BotUser, error)
SaveBotUser(c context.Context, botUserID interface{}, botUserEntity BotUser) error
CreateBotUser(c context.Context, botID string, apiUser WebhookActor) (BotUser, error)
//io.Closer
user.UpdatedTimeSetter // SetUpdatedTime(time.Time) // to satisfy github.com/strongo/app/user.UpdatedTimeSetter
}
22 changes: 22 additions & 0 deletions botsfw/bot_user_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package botsfw

import "context"

//type UserID interface {
// int | string
//}

// BotUserStore provider to store information about bot user
type BotUserStore interface {

// GetBotUserByID returns bot user data
GetBotUserByID(c context.Context, botUserID any) (BotUser, error)

// SaveBotUser saves bot user data
SaveBotUser(c context.Context, botUserID any, botUserData BotUser) error

// CreateBotUser creates new bot user in DB
// Deprecated: should be moved to bots-fw-* package
CreateBotUser(c context.Context, botID string, apiUser WebhookActor) (BotUser, error)
//io.Closer
}
18 changes: 14 additions & 4 deletions botsfw/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ type WebhookContext interface { // TODO: Make interface much smaller?

ChatEntity() BotChat

// IsInGroup indicates if message was received in a group chat
IsInGroup() bool

// CommandText TODO: needs to be documented
CommandText(title, icon string) string

//Locale() strongo.ByLocale

// SetLocale sets locale for current session
SetLocale(code5 string) error

NewMessage(text string) MessageFromBot
Expand All @@ -78,8 +82,8 @@ type WebhookContext interface { // TODO: Make interface much smaller?
//SaveAppUser(appUserID int64, appUserEntity BotAppUser) error

BotState
BotChatStore // TODO: Migrate to strongo/db
BotUserStore // TODO: Migrate to strongo/db
BotChatStore
BotUserStore
WebhookInput // TODO: Should be removed!!!
strongo.SingleLocaleTranslator

Expand All @@ -93,13 +97,19 @@ type BotState interface {

// BotInputProvider provides an input from a specific bot interface (Telegram, FB Messenger, Viber, etc.)
type BotInputProvider interface {
// Input returns a webhook input from a specific bot interface (Telegram, FB Messenger, Viber, etc.)
Input() WebhookInput
}

// BotAPIUser provides info about current bot user
type BotAPIUser interface {
//IdAsString() string
//IdAsInt64() int64
// FirstName returns user's first name
FirstName() string

// LastName returns user's last name
LastName() string

//IdAsString() string
//IdAsInt64() int64

}
2 changes: 1 addition & 1 deletion botsfw/context_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (whcb *WebhookContextBase) loadChatEntityBase() error {
if err != nil {
return err
}
botChatEntity = whcb.BotChatStore.NewBotChatEntity(c, whcb.GetBotCode(), whcb.input.Chat(), botUser.GetAppUserIntID(), botChatID, botUser.IsAccessGranted())
botChatEntity = whcb.BotChatStore.NewBotChatEntity(c, whcb.GetBotCode(), whcb.input.Chat(), botUser.GetAppUserStrID(), botChatID, botUser.IsAccessGranted())

if whcb.GetBotSettings().Env == strongo.EnvProduction {
ga := whcb.gaContext
Expand Down
2 changes: 1 addition & 1 deletion package.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package botsfwframework
package botsframework

// Main code for the package is in the `botsfw` directory.
7 changes: 7 additions & 0 deletions package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package botsframework

import "testing"

func TestPackage(t *testing.T) {
t.Log("Package test")
}

0 comments on commit b7b9961

Please sign in to comment.