Skip to content

Commit

Permalink
feat: handle photo captions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidramiro committed Dec 23, 2024
1 parent b8a8cbf commit 68bb063
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module hsbot
go 1.22

require (
github.com/go-telegram/bot v1.12.0
github.com/go-telegram/bot v1.12.1
github.com/gofrs/uuid/v5 v5.3.0
github.com/liushuangls/go-anthropic/v2 v2.13.0
github.com/rs/zerolog v1.33.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-telegram/bot v1.12.0 h1:5i4lLLOldfv45egxb8m3XDelXU6SBryg3aHFMvmKoFs=
github.com/go-telegram/bot v1.12.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
github.com/go-telegram/bot v1.12.1 h1:2CSwMd+g71/XrmuSpvEjLtsmkfL/s63PdnLboGJQxtw=
github.com/go-telegram/bot v1.12.1/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid/v5 v5.3.0 h1:m0mUMr+oVYUdxpMLgSYCZiXe7PuVPnI94+OMeVBNedk=
github.com/gofrs/uuid/v5 v5.3.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
Expand Down
6 changes: 5 additions & 1 deletion internal/adapters/handler/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ func (h *CommandHandler) Handle(ctx context.Context, b *bot.Bot, update *models.
return
}

if update.Message.Photo != nil {
update.Message.Text = update.Message.Caption
}

log.Debug().Str("message", update.Message.Text).Msg("registering chat command handler")

cmd := domain.ParseCommand(update.Message.Text)
commandHandler, err := h.commandRegistry.Get(cmd)
if err != nil {
log.Debug().Str("commands", cmd).Msg("no handler for commands")
log.Debug().Str("command", cmd).Msg("no handler for command")
return
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/domain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func ParseCommandArgs(args string) string {

func ParseCommand(args string) string {
command := strings.Split(args, " ")
return command[0]
return strings.ToLower(command[0])
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func main() {
commandHandler := handler.NewCommandHandler(commandRegistry, handlerTimeout)

b.RegisterHandler(bot.HandlerTypeMessageText, "/", bot.MatchTypePrefix, commandHandler.Handle)
b.RegisterHandler(bot.HandlerTypePhotoCaption, "/", bot.MatchTypePrefix, commandHandler.Handle)

log.Info().Msg("bot listening")
b.Start(ctx)
Expand Down

0 comments on commit 68bb063

Please sign in to comment.