fix: handle string ID in Todoist user info response
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 6s

This commit is contained in:
Play Life Bot
2026-01-02 15:46:20 +03:00
parent bcea4b2bf5
commit 8f7acee60c

View File

@@ -5888,21 +5888,34 @@ func getTodoistUserInfo(accessToken string) (struct {
log.Printf("Todoist API: parsed response keys: %v", getMapKeys(result))
// Функция для извлечения ID из разных типов
extractID := func(idValue interface{}) int64 {
switch v := idValue.(type) {
case float64:
return int64(v)
case int64:
return v
case int:
return int64(v)
case string:
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
return id
}
}
return 0
}
// Проверяем разные варианты структуры ответа
if userObj, ok := result["user"].(map[string]interface{}); ok {
// Один объект user
if id, ok := userObj["id"].(float64); ok {
userInfo.ID = int64(id)
}
userInfo.ID = extractID(userObj["id"])
if email, ok := userObj["email"].(string); ok {
userInfo.Email = email
}
} else if usersArr, ok := result["user"].([]interface{}); ok && len(usersArr) > 0 {
// Массив users, берем первый
if userObj, ok := usersArr[0].(map[string]interface{}); ok {
if id, ok := userObj["id"].(float64); ok {
userInfo.ID = int64(id)
}
userInfo.ID = extractID(userObj["id"])
if email, ok := userObj["email"].(string); ok {
userInfo.Email = email
}