mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: implement telegram bot plugin (#1740)
This commit is contained in:
@ -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"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user