Skip to content

Commit c135c34

Browse files
committed
feat: add language to callback service
1 parent 03f6860 commit c135c34

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

handlers/bot/callbacks.go

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func (h *handler) Callback(ctx context.Context, tgbot *tgbotapi.BotAPI, update t
4848
msg = h.callback.Information(ctx, msg, user)
4949
case "help":
5050
msg = h.callback.Help(ctx, msg, user)
51+
case "language":
52+
msg = h.callback.Language(ctx, msg, user)
5153
case "backToMain":
5254
msg = h.callback.Menu(ctx, msg, user)
5355
}

pkg/keyboards/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var mainEN = tgbotapi.NewInlineKeyboardMarkup(
2323
tgbotapi.NewInlineKeyboardButtonData("Your Information", "information"),
2424
tgbotapi.NewInlineKeyboardButtonData("Help", "help"),
2525
),
26+
tgbotapi.NewInlineKeyboardRow(
27+
tgbotapi.NewInlineKeyboardButtonData("Choosing another language", "language"),
28+
),
2629
)
2730

2831
// mainFa is main menu in Persian.
@@ -31,4 +34,7 @@ var mainFa = tgbotapi.NewInlineKeyboardMarkup(
3134
tgbotapi.NewInlineKeyboardButtonData("اطلاعات شما", "information"),
3235
tgbotapi.NewInlineKeyboardButtonData("کمک", "help"),
3336
),
37+
tgbotapi.NewInlineKeyboardRow(
38+
tgbotapi.NewInlineKeyboardButtonData("انتخاب زبان دیگر", "language"),
39+
),
3440
)

services/callback.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ type Callback interface {
1313
Menu(ctx context.Context, msg tgbotapi.MessageConfig, user *models.User) tgbotapi.MessageConfig
1414
Help(ctx context.Context, msg tgbotapi.MessageConfig, user *models.User) tgbotapi.MessageConfig
1515
Information(ctx context.Context, msg tgbotapi.MessageConfig, user *models.User) tgbotapi.MessageConfig
16+
Language(ctx context.Context, msg tgbotapi.MessageConfig, user *models.User) tgbotapi.MessageConfig
1617
}

services/callback/language.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// package callback implements callback request functionalities.
2+
package callback
3+
4+
import (
5+
"context"
6+
7+
"github.com/barahouei/clean-architecture-telegram-bot/models"
8+
"github.com/barahouei/clean-architecture-telegram-bot/pkg/keyboards"
9+
"github.com/barahouei/clean-architecture-telegram-bot/pkg/messages"
10+
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
11+
)
12+
13+
// Language shows a select language menu.
14+
func (m *call) Language(ctx context.Context, msg tgbotapi.MessageConfig, user *models.User) tgbotapi.MessageConfig {
15+
msg.Text = messages.Language(user)
16+
msg.ReplyMarkup = keyboards.Language()
17+
18+
return msg
19+
}

0 commit comments

Comments
 (0)