Need Help With Creating Custom Function in Zoho Flow that will Create Merge Document from Template and email it

Need Help With Creating Custom Function in Zoho Flow that will Create Merge Document from Template and email it

I have a Flow that gets triggered every time a deal is updated. When the deal goes to Zoho Flow, I want to use the fields from the deal to create a document using a merge mail template. I already have a Merge Template. I just need to have a custom function that I can use in Zoho Flow to tell the merge template to create a document from that template,  pulling in the merge tags from the deal per the template specifications. I then want the custom function to email the new merged document to an email from the deal. I know that this is possible but I need help with the custom function code. Can you please help?

Thanks in advance for helping!