How to call the API after certain interval when token expires?

Use Case: Refresh Token
Hi ,
Through mobile app we are getting payloads, when we are opening bot. In payload we are getting access token, which has expiry timing set. While using the bot if the access token gets expire we need to call the Refresh token API, which will give us new access token with expiry time.So in Bot we are trying to implement in that way , after open the bot , we are calling refresh token API and we received new access token with expiry time. So once timer is reached we need to again call the refresh token API again.
How to call the API after certain interval when token expires?
kindly suggest any alternative for this.
platform :- onprem

Why are you passing the access token in payload? Please use API integration in bot to fetch the access-token and refresh it when required.