Optin to a token through a wallet within the App


I want to code something in a way that whenever a new asset is transferred to the user which is not optin to the user’s wallet. How can I optin using code?

Because without optin the new asset to user’s wallet, we can transfer it to user’s accounts? So how we can achieve this within the code?

Take a look at receiving an asset here: