How to update a Telegram bot without losing enquiries
Updating the Telegram bot affects not only program files. At the time of release, users can fill out a form, submit documents, and click buttons from old messages. The notification queue, enquiry database and integration with CRM operate simultaneously. If you simply replace the code and restart the process, some of these workflows may be interrupted.
The previously described update procedure helps reduce the risk: prepare a copy, test the new version separately, save incoming events and make sure that requests continue to be processed. A complete absence of failures cannot be promised by one deployment method. Below is a practical plan for a business owner and developer to agree on a release and review.
1. Map the enquiry workflow
Before updating, make a short diagram: where the message comes from, where the request is saved, which process sends the notification and when the request appears to the manager. Note which components depend on the bot and which work separately. For example, receiving an incoming event and sending a letter can be performed by different handlers, which are updated independently.
Check where the pending dialog is stored. If a questionnaire step exists only in process memory, a restart may lose it. List attachments, pending jobs, and external identifiers separately. It is convenient to associate the diagram with a description of the path of the enquiry to the manager. Then the specific result is checked, and not just the presence of a response to the launch command.
2. Prepare a backup and rollback plan
Save the current version of the code, database structure, data, launch settings and necessary files. The copy must be outside the directory that replaces the release. Check the composition of the archive and the availability of the recovery procedure. The presence of a file called backup does not prove that it contains client documents or a queue of unprocessed jobs.
Separate code return and data recovery. After the launch of the new version, new requests could appear; restoring the old database over the working one can remove them. Therefore, the rollback plan must take into account the requests saved during this time. Practical issues of composition and verification of copies are discussed in the article about backup. Before release, determine who makes the decision to stop and where progress is recorded.
3. Check how incoming events are saved
Telegram has two mutually exclusive ways to receive updates: webhook and getUpdates. According to Bot API documentation, unreceived events are not stored longer than 24 hours. This queue should not be considered long-term backup storage. It is important for the workflow to have its own persistent persistence of received events and clear error handling.
When setting up a webhook and deleting it, the drop_pending_updates parameter removes pending updates if enabled. Do not use it as a normal release cleaning operation. With a webhook, confirmation of reception should be associated with reliable storage of the event, and not with a promise to process it later in memory. For getUpdates, coordinate the moment of promotion offset with saving and processing: an incorrect confirmation can exclude requests that have not yet been processed from being received again.
4. Make retries safe
Replaying an incoming event should not create another request or re-send a confirmed notification. Store a persistent event identifier along with the result of its processing. The retry check must be able to withstand simultaneous queries and not run as a separate lookup before an unrelated save. Otherwise, two handlers may simultaneously decide that the event is not yet known.
In this case, a new request from the same client is not necessarily a duplicate. He could request another service or clarify the task. Separate repeat delivery and new business action. External sending also requires attention: if the CRM accepted the record but the response got lost, a simple retry can create a second card. The rules for such cases are discussed in the material about duplicate enquiries in CRM.
5. Keep existing workflows compatible
Users are not required to start the conversation again after updating. Check the saved survey steps and buttons in previously sent messages. If an action is no longer supported, the bot should explain the next step rather than silently ending the request. Old messages and links can be used even after the new version is already running.
Coordinate changes in the database structure with the order of process switching. Adding a new optional field is usually easier to reconcile with the previous version than renaming or removing an existing field. The exact plan depends on the application, but releasing code and changing data should not conflict with each other. Prepare tests for both versions if they are running in parallel for some time or if you intend to revert to the previous code.
6. Release the tested version in stages
Test the update first in a separate environment on synthetic data. Do not connect a test handler to a production bot without a well-thought-out scheme for receiving events. To test, use a separate bot and disabled or test external assignments. Accidentally sending service messages to real clients should not become part of the release review.
On the production server, prepare the new version separately and only run consistent data changes before switchover where it is compatible with the old version. Consider active tasks: complete them gracefully or consider re-executing them after stopping. Do not run multiple getUpdates recipients independently for the same bot. After switching, first check the technical readiness, then the actual saving of the test request and its availability to the manager.
7. Check enquiries, queues and rollback readiness
After release, compare incoming events, saved enquiries and results of sending to CRM. Check not only the quantity, but also the relationship of specific records: identical total numbers do not exclude omissions and repetitions. Look at outstanding jobs, wait times, and new errors. If the queue is growing, a running process does not mean that it can cope with incoming requests.
Check a regular message, a document, an old button, an interrupted dialog, and a retry event. For the operator scenario, make sure that the new version does not take away an already submitted request from the employee. If the agreed rollback conditions are met, stop further changes and proceed with the prepared plan. Save new enquiries and journals for reconciliation; Do not automatically restore an old copy over data created after release.
What to agree before the next update
In the release task, indicate the composition of the changes, how events are received, where the queue is stored, database changes, test workflows, and who is responsible for the rollback decision. After the work, save a short report: which version is installed, what has been checked and what restrictions remain. Monitoring after release should continue until the accumulated tasks are processed, and not end with the bot’s first response.
For the general organization of work, the material about the connection between a Telegram bot and CRM is useful. Describe your bot, integrations and planned update in the brief – this will help determine the preparation, release procedure and verification criteria without transferring tokens in correspondence.