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

Request to automatically refresh the access token in unofficial mode #13

Closed churchmice closed 1 year ago

churchmice commented 1 year ago

HI, first thanks for the great project. I have set it up and running fine with the 'unofficial' api_type. However, the access token seems will be invalid for roughly every 8 hours. From the linked resource, I find a script to get the access token, as described in https://github.com/acheong08/OpenAIAuth.

I am wondering whether this can be integrated into the bot to make it refresh the token automatically once it is invalid ? My current approach is writing a crontab job to get the token, update the config file and restart the bot, which is not elegant.

Anyhow, thanks for your great work.

RainEggplant commented 1 year ago

Thank you for using this bot.

Before implementing auto-refresh of the access token, more information about the following questions is needed:

If the answers to these questions are negative, we may have to use acheong08/OpenAIAuth to refresh the token. However, integrating Python scripts into a Node project is not the most elegant solution. It would be ideal to have a Node package that handles this.

Update: I have found some node.js ports of the OpenAIAuth (ericlewis/openai-authenticator, michael-dm/openai-token). And I believe Travis will implement the auto-refresh feature in the upstream API if necessary. So let's wait a little bit 😂.

churchmice commented 1 year ago

I see your points. Thank you. I tried to send /reload command after the session expires, and it works.

RainEggplant commented 1 year ago

@churchmice You're welcome. You can actually send messages as usual, instead of sending /reload (which clears the conversation context)

kintong3000 commented 1 year ago

Looking forward to the this function

kintong3000 commented 1 year ago

how to Obtain admin authority

image
RainEggplant commented 1 year ago

how to Obtain admin authority

@kintong3000 Add your telegram user id to bot.userIds in the config file.

kintong3000 commented 1 year ago

how to Obtain admin authority

@kintong3000 Add your telegram user id to bot.userIds in the config file.

thanks!

RainEggplant commented 1 year ago

Closed as the access token lasts for a month and gets renewed at each request.