How to add event handler to an element added through a designer extension

I am trying to create an extension which helps users to add otp verification feature to their website. In order to do that, I am planning to provide an option to add a new button (send otp), is there a way to ship an event handler function for onclick event, for the added button ? If possible, then I need to pass the recipients phone number as a dynamic value to the event handler function. How can I obtain the values for the dynamic variable , at the time of execution?

Custom code may be a good approach in this case. You can programmatically add custom code via the Data APIs (or manually by suggesting to the user)