feat: implement telegram bot plugin (#1740)

This commit is contained in:
Athurg Gooth
2023-05-26 09:43:51 +08:00
committed by GitHub
parent a07d11e820
commit 1282fe732e
23 changed files with 577 additions and 15 deletions

View File

@@ -34,6 +34,8 @@ const (
SystemSettingLocalStoragePathName SystemSettingName = "local-storage-path"
// SystemSettingOpenAIConfigName is the name of OpenAI config.
SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
// SystemSettingTelegramRobotToken is the name of Telegram Robot Token.
SystemSettingTelegramRobotTokenName SystemSettingName = "telegram-robot-token"
)
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
@@ -83,6 +85,8 @@ func (key SystemSettingName) String() string {
return "local-storage-path"
case SystemSettingOpenAIConfigName:
return "openai-config"
case SystemSettingTelegramRobotTokenName:
return "telegram-robot-token"
}
return ""
}

View File

@@ -16,6 +16,8 @@ const (
UserSettingAppearanceKey UserSettingKey = "appearance"
// UserSettingMemoVisibilityKey is the key type for user preference memo default visibility.
UserSettingMemoVisibilityKey UserSettingKey = "memo-visibility"
// UserSettingTelegramUserID is the key type for telegram UserID of memos user.
UserSettingTelegramUserIDKey UserSettingKey = "telegram-user-id"
)
// String returns the string format of UserSettingKey type.
@@ -27,6 +29,8 @@ func (key UserSettingKey) String() string {
return "appearance"
case UserSettingMemoVisibilityKey:
return "memo-visibility"
case UserSettingTelegramUserIDKey:
return "telegram-user-id"
}
return ""
}
@@ -96,6 +100,15 @@ func (upsert UserSettingUpsert) Validate() error {
if !slices.Contains(UserSettingMemoVisibilityValue, memoVisibilityValue) {
return fmt.Errorf("invalid user setting memo visibility value")
}
} else if upsert.Key == UserSettingTelegramUserIDKey {
telegramUserID := 0
err := json.Unmarshal([]byte(upsert.Value), &telegramUserID)
if err != nil {
return fmt.Errorf("failed to unmarshal user setting telegram userid value")
}
if telegramUserID <= 0 {
return fmt.Errorf("invalid user setting telegram userid value")
}
} else {
return fmt.Errorf("invalid user setting key")
}
@@ -104,7 +117,7 @@ func (upsert UserSettingUpsert) Validate() error {
}
type UserSettingFind struct {
UserID int
UserID *int
Key UserSettingKey `json:"key"`
}