flynnoct / chatgpt-telegram-bot

Telegram bot implemented by OFFICIAL OpenAI ChatGPT API (gpt-3.5-turbo, released on 2023-03-01)
MIT License
182 stars 44 forks source link

telegram bot reply nothing #13

Closed peteisacat closed 1 year ago

peteisacat commented 1 year ago

I followed the prompts in the instructions for installation, and at the end it showed that the bot has started successfully. However, I'm not receiving any replies from the bot when I send messages to it. I don't know why.

flynnoct commented 1 year ago

Can you get a reply message when you send "/start" command to your bot?

dtimekeeper commented 1 year ago

Hmm, same issue here, sending /start shows 2 tick marks in Telegram for read but no reply, and the bot shows as started without any errors. Is there a debug log maybe?

peteisacat commented 1 year ago

Can you get a reply message when you send "/start" command to your bot?

No matter what message I send, my robot won't respond with any content。

flynnoct commented 1 year ago

Hmm, same issue here, sending /start shows 2 tick marks in Telegram for read but no reply, and the bot shows as started without any errors. Is there a debug log maybe?

Sorry, we didn't have a good logging for now :(, I promise we will do this in a few days. Would you mind following these introductions:

  1. cd to the work directory, it's <somewhere>/chatgpt-telegram-bot
  2. execute python3 telegram_message_parser.py
  3. try to send a message to your bot and check if there is any traceback prompt in your terminal.

Apologize for not having good outputs and loggings again. @dtimekeeper @peteisacat

dtimekeeper commented 1 year ago

No worries - thank you for your response. I’ve ran the telegram_message_parser.py with the output below:

aaron@artemis:~/chatgpt-dalle-telegram$ python3 telegram_message_parser.py
Traceback (most recent call last):
  File "/home/aaron/chatgpt-dalle-telegram/telegram_message_parser.py", line 21, in <module>
    config_dict = json.load(f)
  File "/home/aaron/anaconda3/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/home/aaron/anaconda3/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/home/aaron/anaconda3/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/aaron/anaconda3/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 4 column 29 (char 184)
(base) aaron@artemis:~/chatgpt-dalle-telegram$

Please let me know if there’s anything else I can provide.

flynnoct commented 1 year ago

@dtimekeeper Looks like a config file error. Would you mind paste your config.json contents below?

DO Make sure to hide both of your openai_api_key and telegram_bot_token, just replace them with placeholders.

dtimekeeper commented 1 year ago

Sure thing:

{ 
"openai_api_key": "xxx",
"telegram_bot_token": "xxx",
"enable_voice": true,   // When enabled, Bot will accept audio messages with Whisper and reply.
"allowed_users": [ 
"xxx",
], 
"wait_time": 600,   // The time limit in seconds that the Bot will clear the conversation context.
"enable_dalle": true,   // When enabled, Bot will involve DALL·E to handle requests for painting.
"super_users": [ 
"xxx",    // Super users are granted unlimited usage on DALL·E per day.
], 
"image_generation_limit_per_day": 5     // The upper limit that a normal user is allowed to invoke DALL·E per day.
}
flynnoct commented 1 year ago

I think the problem could come from invalid comments in the JSON file.

Try removing all comments in your config.json file which means removing all // some comments and start again. I think it should work.

We actually should comment the keys in a better way. We will fix that in next version. Thanks.

dtimekeeper commented 1 year ago

I believe I’ve cleaned out the comments but still get the error - at least it’s a different line now? :):

(base) aaron@artemis:~/chatgpt-dalle-telegram$ python3 telegram_message_parser.py
Traceback (most recent call last):
  File "/home/aaron/chatgpt-dalle-telegram/telegram_message_parser.py", line 21, in <module>
    config_dict = json.load(f)
  File "/home/aaron/anaconda3/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/home/aaron/anaconda3/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/home/aaron/anaconda3/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/aaron/anaconda3/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 7 column 5 (char 228)
(base) aaron@artemis:~/chatgpt-dalle-telegram$ 
{
����"openai_api_key": "xxx",
����"telegram_bot_token": "xxx",
����"enable_voice": true,
����"allowed_users": [
��������"xxx",
����],
����"wait_time": 600,
����"enable_dalle": true,
����"super_users": [
��������"xxx",
����], 
����"image_generation_limit_per_day": 5
}

The Telegram bot key has some funky letters like ___ and : so maybe it might be that?

flynnoct commented 1 year ago

@dtimekeeper Both allowed_users and super_users are JSON lists. Elements inside should be split with commas(,), however, no comma needed after last element.

So try removing commas in line 6 and line 11.

dtimekeeper commented 1 year ago

Boom, that was it and it’s up and running like a charm. Thank you, sir.

Really also appreciate that your code has the routine to clear the conversation after x seconds so I can always start fresh instead of manually clearing it.

flynnoct commented 1 year ago

@dtimekeeper A robust program should work in this way. Glad you like it.

If there's more advices or suggestions please let me know.

flynnoct commented 1 year ago

@peteisacat Consider follow the instructions above. This may help you solve the problem.

dtimekeeper commented 1 year ago

@dtimekeeper A robust program should work in this way. Glad you like it.

If there's more advices or suggestions please let me know.

It really should, but neither of the 3-4 other python options I tried had that.

Suggestions wise, one of use cases is basically running another instance for my friends to use as a telegram bot. It would be helpful to have a way to ‘whitelist’ all telegram IDs so as long as they know the link to message it, they can talk to the bot.

Related to this too, but not sure how feasible it is, would be separate conversational context for each person that messages the bot, but I’m also not sure if this is even possible with the API.

Thanks again.

flynnoct commented 1 year ago

@dtimekeeper Thanks for your suggestions.

Would you mind copy and paste these suggestions to a new issue that I can easily work with? I will have a conversation with you there. Thanks.

peteisacat commented 1 year ago

@peteisacat Consider follow the instructions above. This may help you solve the problem.

@flynnoct Thank you very much. I have successfully run it according to the method you described above. Thank you for your hard work.😄❤️