So for Android, everything is visible to appium, so you can hit home button (adb shell input keyevent 3), navigate to your SMS default app and read the OTP. The hard part in here will be making a code broad enough to cover most of Android models.
On iOS go to Settings --> Notifications --> Messages and choose the Alerts style for your SMS. Once the OTP reaches the device, an alert is displayed containing the initial part of your SMS. With lucky your OTP will be visible there and appium can see that message. Downside is that for any SMS your device receives that alert will be triggered.