How to Recover Deleted Messages
There are six potential avenues for recovering deleted messages: you may be able to restore a message from your Recently Deleted folder; you can recover them through a backup; you can try retrieving the message from your SMS app (such as Google's Messages app); you can get in touch with your carrier to see about a lost text message recovery; or you can use a third-party program. Each has its own pros and cons, so consider each option carefully based on your specific situation.
First, make sure the deleted messages haven't been overwritten. The longer you wait, the more likely they will be overwritten by new data or even by new messages from the same conversation. If you're using an Android phone, check if your SMS app has a recycle bin or similar feature that holds deleted messages for a certain period of time. For example, Google's Messages app has an archived messages folder. You can also try this for other popular messaging apps like Samsung's Messages.
If you're using an iPhone, the best option is to restore a previous backup. This requires resetting the device to factory settings and then restoring a backup from before you erased the messages. The problem is that this process erases all of your data on the device, so any subsequent messages will be overwritten.
For other Android phones, you can use a tool like EaseUS MobiSaver. These programs can scan the device for deleted text messages and retrieve them to your computer. They're not foolproof and won't work every time, but they might be worth a shot.