dreamhunter2333 / cloudflare_temp_email

CloudFlare free temp domain email 免费收发 临时域名邮箱 支持附件 IMAP SMTP TelegramBot
https://mail.awsl.uk
MIT License
2.15k stars 801 forks source link

feat: telegram Set manually to avoid implicit call in or #442

Closed dreamhunter2333 closed 3 weeks ago

dreamhunter2333 commented 3 weeks ago

User description

441


PR Type

Enhancement, Documentation


Description


Changes walkthrough 📝

Relevant files
Enhancement
telegram.ts
Set Telegram bot info from environment variable to reduce latency

worker/src/telegram_api/telegram.ts
  • Added retrieval of botInfo from environment variable TG_BOT_INFO.
  • Set bot.botInfo if botInfo is available to reduce latency.
  • Imported getJsonObjectValue utility function.
  • +6/-1     
    types.d.ts
    Add TG_BOT_INFO to Bindings type                                                 

    worker/src/types.d.ts - Added `TG_BOT_INFO` to `Bindings` type.
    +1/-0     
    utils.ts
    Add utility function to parse JSON values                               

    worker/src/utils.ts - Added `getJsonObjectValue` utility function to parse JSON values.
    +20/-0   
    Documentation
    CHANGELOG.md
    Update changelog with new bot info feature                             

    CHANGELOG.md - Updated changelog to include new feature for setting bot info.
    +4/-0     
    cli.md
    Document TG_BOT_INFO environment variable                               

    vitepress-docs/docs/en/cli.md - Documented new `TG_BOT_INFO` environment variable.
    +2/-0     
    worker.md
    Document TG_BOT_INFO environment variable in Chinese         

    vitepress-docs/docs/zh/guide/cli/worker.md - Documented new `TG_BOT_INFO` environment variable in Chinese.
    +2/-0     
    wrangler.toml.template
    Add TG_BOT_INFO to configuration template                               

    worker/wrangler.toml.template - Added `TG_BOT_INFO` to configuration template.
    +2/-0     

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    github-actions[bot] commented 3 weeks ago

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    The `getJsonObjectValue` function logs an error when JSON parsing fails but does not propagate the error. Consider whether this is the desired behavior or if the error should be handled differently.
    github-actions[bot] commented 3 weeks ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check to ensure the environment variable exists before parsing it ___ **Add a check to ensure c.env.TG_BOT_INFO exists before calling getJsonObjectValue to
    avoid potential runtime errors.** [worker/src/telegram_api/telegram.ts [48-51]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/442/files#diff-a62d9c6ad0b04691396db4eecb38680ea80a2690f021e18baa6012ad525a27d3R48-R51) ```diff -const botInfo = getJsonObjectValue(c.env.TG_BOT_INFO); +const botInfo = c.env.TG_BOT_INFO ? getJsonObjectValue(c.env.TG_BOT_INFO) : null; if (botInfo) { bot.botInfo = botInfo; } ```
    Suggestion importance[1-10]: 9 Why: This suggestion adds a necessary check to prevent potential runtime errors if `c.env.TG_BOT_INFO` is undefined, improving the robustness of the code.
    9
    Enhancement
    Improve error logging by including the error message ___ **Improve error logging by including the error message in the log output.** [worker/src/utils.ts [20]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/442/files#diff-87b77c56897ffc7830773b3d665c51ecf2210b44921bef7098a1dd6d64e56db6R20-R20) ```diff -console.error(`GetJsonValue: Failed to parse ${value}`, e); +console.error(`GetJsonValue: Failed to parse ${value}: ${e.message}`, e); ```
    Suggestion importance[1-10]: 8 Why: Including the error message in the log output provides more detailed information for debugging, enhancing the maintainability of the code.
    8
    Best practice
    Simplify the null or undefined check for better readability ___ **Simplify the null or undefined check for `value` by using a single condition.** [worker/src/utils.ts [8-9]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/442/files#diff-87b77c56897ffc7830773b3d665c51ecf2210b44921bef7098a1dd6d64e56db6R8-R9) ```diff -if (value == undefined || value == null) { +if (value == null) { return null; } ```
    Suggestion importance[1-10]: 7 Why: The suggestion simplifies the null or undefined check, making the code more readable and concise without changing its functionality.
    7