From ba7534e59067e8ab246465f0a7aeea0d044027fc Mon Sep 17 00:00:00 2001 From: wolfsilver Date: Tue, 27 Aug 2024 08:05:26 +0800 Subject: [PATCH] fix: url in bot message (#50) * fix: url in bot message * Update .env.example Co-authored-by: boojack <24653555+boojack@users.noreply.github.com> * feat: rename MEMOS_ADDR to INSTANCE_URL * feat: rename MEMOS_ADDR to INSTANCE_URL * feat: rename MEMOS_ADDR to INSTANCE_URL * fix: formatting --------- Co-authored-by: boojack <24653555+boojack@users.noreply.github.com> --- .env.example | 3 ++- README.md | 2 ++ config.go | 7 ++++--- memogram.go | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 72d17c3..26e8df9 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ SERVER_ADDR=dns:localhost:5230 -BOT_TOKEN=your_bot_token \ No newline at end of file +BOT_TOKEN=your_bot_token +INSTANCE_URL=https://memos.example.com diff --git a/README.md b/README.md index af3743d..89c3167 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Create a `.env` file in the project's root directory and add the following confi ```env SERVER_ADDR=dns:localhost:5230 BOT_TOKEN=your_telegram_bot_token +INSTANCE_URL=https://memos.example.com ``` The `SERVER_ADDR` should be a gRPC server address that the Memos is running on. It follows the [gRPC Name Resolution](https://github.com/grpc/grpc/blob/master/doc/naming.md). @@ -64,6 +65,7 @@ Or you can start the service with Docker Compose. This can be combined with the ```sh SERVER_ADDR=dns:yourMemosUrl.com:5230 BOT_TOKEN=your_telegram_bot_token + INSTANCE_URL=https://memos.example.com ``` 4. Create Docker Compose `docker-compose.yml` file: ```yaml diff --git a/config.go b/config.go index 14eb4f9..5a1b186 100644 --- a/config.go +++ b/config.go @@ -10,9 +10,10 @@ import ( ) type Config struct { - ServerAddr string `env:"SERVER_ADDR,required"` - BotToken string `env:"BOT_TOKEN,required"` - Data string `env:"DATA"` + ServerAddr string `env:"SERVER_ADDR,required"` + BotToken string `env:"BOT_TOKEN,required"` + InstanceUrl string `env:"INSTANCE_URL"` + Data string `env:"DATA"` } func getConfigFromEnv() (*Config, error) { diff --git a/memogram.go b/memogram.go index f28f897..9632b0e 100644 --- a/memogram.go +++ b/memogram.go @@ -177,7 +177,7 @@ func (s *Service) handler(ctx context.Context, b *bot.Bot, m *models.Update) { b.SendMessage(ctx, &bot.SendMessageParams{ ChatID: m.Message.Chat.ID, - Text: fmt.Sprintf("Content saved as %s with [%s](%s/m/%s)", v1pb.Visibility_name[int32(memo.Visibility)], memo.Name, s.config.ServerAddr, memo.Uid), + Text: fmt.Sprintf("Content saved as %s with [%s](%s/m/%s)", v1pb.Visibility_name[int32(memo.Visibility)], memo.Name, s.config.InstanceUrl, memo.Uid), ParseMode: models.ParseModeMarkdown, DisableNotification: true, ReplyParameters: &models.ReplyParameters{