{"record":{"id":"bad7a476eb66d1c8","repo":"larksuite/cli","slug":"fetch-bot-info-bot-identity-is-not-available-in-c","errorCode":null,"errorMessage":"fetch bot info: bot identity is not available in current credential context","messagePattern":"fetch bot info: bot identity is not available in current credential context","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/runner.go","lineNumber":161,"sourceCode":"}\n\n// BotInfo returns the bot's open_id and display name, fetched lazily from /bot/v3/info.\n// Unlike UserOpenId() (which reads from config), this requires a network call and may fail.\n// Thread-safe via sync.OnceValues; the API is called at most once per RuntimeContext.\nfunc (ctx *RuntimeContext) BotInfo() (*BotInfo, error) {\n\tif ctx.offline {\n\t\treturn nil, errs.NewValidationError(errs.SubtypeFailedPrecondition, \"BotInfo is unavailable during dry-run\")\n\t}\n\tif ctx.botInfoFunc == nil {\n\t\treturn nil, fmt.Errorf(\"BotInfo not available (runtime context not fully initialized)\")\n\t}\n\treturn ctx.botInfoFunc()\n}\n\n// fetchBotInfo calls /bot/v3/info using bot identity and parses the response.\nfunc (ctx *RuntimeContext) fetchBotInfo() (*BotInfo, error) {\n\tif !ctx.Config.CanBot() {\n\t\treturn nil, fmt.Errorf(\"fetch bot info: bot identity is not available in current credential context\")\n\t}\n\tresp, err := ctx.DoAPIAsBot(&larkcore.ApiReq{\n\t\tHttpMethod: http.MethodGet,\n\t\tApiPath:    \"/open-apis/bot/v3/info\",\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"fetch bot info: %w\", err)\n\t}\n\tif resp.StatusCode >= 400 {\n\t\treturn nil, fmt.Errorf(\"fetch bot info: HTTP %d\", resp.StatusCode)\n\t}\n\t// /open-apis/bot/v3/info returns `{code, msg, bot: {...}}` — the bot\n\t// payload is under \"bot\", not \"data\" as the newer Lark API convention.\n\tvar envelope struct {\n\t\tCode int    `json:\"code\"`\n\t\tMsg  string `json:\"msg\"`\n\t\tData struct {\n\t\t\tOpenID  string `json:\"open_id\"`","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/runner.go#L143-L179","documentation":"fetchBotInfo refuses to call /bot/v3/info when the current credential context cannot act as a bot (ctx.Config.CanBot() is false). The configured credentials are user/tenant tokens without a bot app identity, so bot info is unobtainable. This is a configuration/credential-shape problem, not a network failure.","triggerScenarios":"BotInfo() called while the active config lacks bot credentials — e.g. user access token auth only, an app without bot capability enabled, or credentials for an app type that cannot call bot APIs.","commonSituations":"Running a shortcut that resolves the attendee/identity from bot info while the CLI is authenticated with a non-bot app; enabling a bot-dependent feature under credentials configured for plain API access.","solutions":["Configure bot-capable credentials (app credentials for an app with the Lark bot capability enabled) in the active profile","Switch to a profile/credential context that CanBot() before running the command","Avoid the bot path: provide the identity explicitly (e.g. pass the ID or use a different identity source flag) instead of deriving it from bot info"],"exampleFix":"// before\nid, err := ctx.selfAttendeeId() // fails with non-bot creds\n// after\nif !ctx.Config.CanBot() { return errs.NewValidationError(errs.SubtypeFailedPrecondition, \"this command requires bot credentials; configure a bot-enabled app\") }","handlingStrategy":"validation","validationCode":"if !ctx.Config.CanBot() {\n\treturn errs.NewValidationError(errs.SubtypeFailedPrecondition, \"requires bot credentials\")\n}\ninfo, err := ctx.BotInfo()","typeGuard":"func canUseBotIdentity(ctx *common.RuntimeContext) bool { return ctx.Config.CanBot() }","tryCatchPattern":"info, err := ctx.BotInfo()\nvar ve *errs.ValidationError\nif errors.As(err, &ve) || strings.Contains(err.Error(), \"bot identity is not available\") {\n\t// fall back to explicit identity flag or ask user to configure bot creds\n}","preventionTips":["Verify the active profile's credentials are bot-capable before bot-dependent commands","Enable the bot capability in the Lark developer console for the configured app","Provide an explicit identity flag as an alternative to deriving it from bot info"],"tags":["go","credentials","bot-identity","configuration"],"backgroundTag":"bot-credentials-missing","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}