RainEggplant / chatgpt-telegram-bot

A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-base APIs.
MIT License
323 stars 97 forks source link

Some markdown characters are not escaped when sent to Telegram #34

Closed memoz closed 1 year ago

memoz commented 1 year ago

I asked ChatGPT to give a step-by-step guide on how to setup a DNS Cache server that can verify DNSSEC on Debian 11, but the response was cut off on Telegram:

ChatGPT, [3/8/2023 10:56 AM] Sure

This is the corresponding log at debug level 2:

3/8/2023, 2:56:14 AM 📩 Message from [redacted] in group [redacted]: Can you give the exact steps on Debian 11 sendMessage (460 tokens) { max_tokens: 1000, model: 'gpt-3.5-turbo', temperature: 0.8, top_p: 1, presence_penalty: 1, messages: [ { role: 'system', content: 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\n' + 'Knowledge cutoff: 2021-09-01\n' + 'Current date: 2023-03-08' }, { role: 'user', content: 'How to set up a DNS Cache server that can verify DNSSEC on linux', name: undefined }, { role: 'assistant', content: 'To set up a DNS cache server that can verify DNSSEC on Linux, you can follow these general steps:\n' + '\n' + '1. Install a DNS server software, such as BIND or Unbound, on your Linux machine.\n' + '\n' + '2. Configure the DNS server to act as a caching resolver by enabling recursive queries and setting up forwarders or root hints.\n' + '\n' + '3. Enable DNSSEC validation in the DNS server configuration by adding the necessary options and trust anchors (root keys) for DNSSEC validation.\n' + '\n' + "4. Test the DNS server's DNSSEC validation by querying DNSSEC-signed domains and verifying that the answers contain valid DNSSEC signatures.\n" + '\n' + 'Here are some more specific resources that can guide you through the process based on the DNS server software you choose:\n' + '\n' + '- BIND: https://kb.isc.org/docs/aa-00544\n' + '- Unbound: https://nlnetlabs.nl/documentation/unbound/howto-anchor/', name: undefined }, { role: 'user', content: 'How to set up a DNS Cache server that can verify DNSSEC on linux', name: undefined }, { role: 'assistant', content: 'To set up a DNS cache server that can verify DNSSEC on Linux, you can follow these general steps:\n' + '\n' + '1. Install a DNS server software, such as BIND or Unbound, on your Linux machine.\n' + '\n' + '2. Configure the DNS server to act as a caching resolver by enabling recursive queries and setting up forwarders or root hints.\n' + '\n' + '3. Enable DNSSEC validation in the DNS server configuration by adding the necessary options and trust anchors (root keys) for DNSSEC validation.\n' + '\n' + "4. Test the DNS server's DNSSEC validation by querying DNSSEC-signed domains and verifying that the answers contain valid DNSSEC signatures.\n" + '\n' + 'Here are some more specific resources that can guide you through the process based on the DNS server software you choose:\n' + '\n' + '- BIND: https://kb.isc.org/docs/aa-00544\n' + '- Unbound: https://nlnetlabs.nl/documentation/unbound/howto-anchor/', name: undefined }, { role: 'user', content: 'Can you give the exact steps on Debian 11', name: undefined } ], stream: true } 3/8/2023, 2:56:23 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:26 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:29 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:32 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:35 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:38 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:41 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:43 AM ⛔️ Edit message error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\' 3/8/2023, 2:56:43 AM 📨 Response: Sure! Here are the steps to set up a DNS cache server that can verify DNSSEC on Debian 11 using Unbound:

  1. Install Unbound by running the following command:

    sudo apt-get update
    sudo apt-get install unbound
  2. Configure Unbound as a caching resolver and enable DNSSEC validation by editing the /etc/unbound/unbound.conf configuration file. You can use your favorite text > editor to open the file, for example:

    sudo nano /etc/unbound/unbound.conf

    Then add the following configuration options at the end of the file:

    server:
    # Use root hints for resolving instead of forwarders
    # If you prefer to use forwarders, replace with "forward-zone"
    # and add "forward-addr" lines with the IP addresses of your forwarders
    root-hints: "/etc/unbound/root.hints"
    
    # Enable recursive queries
    do-recursion: yes
    
    # Enable DNSSEC validation
    auto-trust-anchor-file: "/var/lib/unbound/root.key"
    val-clean-additional: yes
  3. Download the root key file for DNSSEC validation by running the following command:

    sudo unbound-anchor -a "/var/lib/unbound/root.key"
  4. Restart the Unbound service to apply the changes:

    sudo systemctl restart unbound
  5. Test the DNS server's DNSSEC validation by querying DNSSEC-signed domains and verifying that the answers contain valid DNSSEC signatures. For example, you can use > the dig command to query the example.com domain and check its DNSSEC status:

    dig +dnssec @127.0.0.1 example.com

That's it! Your DNS cache server is now set up to verify DNSSEC on Debian 11 using Unbound.

Node version is 18.14.2. Bot version is 2.3.2.

memoz commented 1 year ago

A small update: I added if (this.debug >= 2) logWithTime("⚠️ Escaped message:", text); to see what's going on and found that <!----> is sometimes present where newlines are. The exact conditions are unknown since if I restart the bot, it goes away and comes back from time to time.

RainEggplant commented 1 year ago

@memoz Hi! I've created an issue in the telegramifyMarkdown repo. I'll update the package once it gets fixed.