There are probably a lot of different ways this is done, but here is one (note that this would require using an ESP32 rather than an ESP8266 because we need BLE):
Your IoT device advertises its presence over BLE. It also advertises a service and characteristics will can be used to send it configuration information.
You have your own custom app running on the customer's phone. It detects the BLE device, possibly asks for a few configuration questions, gets the WiFi credentials from the phone, and sends them to the device over BLE using the aforementioned characteristics.
Your device receives the configuration, saves it, and configures WiFi to connect to the network.
Now the smartphone and device can continue their "discussion" over Wi-Fi.
Surprisingly, even on iOS it's possible to get the current Wi-Fi configuration info, including SSID (the network name) and credentials (password), provided you meet some conditions.
See https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo for documentation on how to do this on iOS and https://izziswift.com/get-the-currently-connected-wifi-informations-in-swift-4-x/ for an example.
I'm pretty sure you can do the same on Android, I'm just too lazy to look that up right now. As others would say: "left as an exercise for the reader"...