Modifying existing Macro with module

Is there a way to modify the “macro-hangupcall” with a module? I can’t seem to find documentation on this. Basically what I am looking to do is to hook into this and send an email after a call is hung up. I have found the dial plan code that is supposed to send the email after a hangup a forum post but I can’t post the link because I am a new user so below is the snippet. I basically just want to modularize this instead of creating adding the code below inside of the extensions_custom.conf file

[macro-hangupcall-custom]
exten => s,1,DumpChan()
exten => s,n,System(echo ‘Call from ${CALLERID(name)} at ${CALLERID(number)}’ | mail -s ‘SUBJECT’ ‘[email protected]’)
exten => s,n,MacroExit()

Thanks in advance

You can rewrite the macro, but far better to do a hook as explained at the bottom of this post:

Would you be able to provide a snippet of the FreePBX module PHP code required to start off with something like this? The post you linked describes how to manually add it to a file but I am looking to do this with a module so no files have to be manually edited. I am not finding any documentation on how to create these contexts using the provided FreePBX PHP API. I have the module skeleton started already, I assume I would add the code inside of the “doDialPlanHook” method of my module class?

I have figured how how to add these to the dialplan using a php module. However the hook only seems to get called after calling an extension. I can confirm this by looking at the description inside of extensions.conf. Is there a hook I can use that will execute after any agent hangs up, regardless if they received a call from a queue, direct extension dial or outbound call?

Somewhat off topic, but most IP phones can be configured to access a URL on various events, including when a call is ended. Variables can be used to transmit the calling and called numbers, call duration, etc. for example, see
http://support.yealink.com/attachmentDownload/download?path=upload%2FtrainingAttachment%2F2017-2-12%2F2%2F2b2185ce-cc67-4ac1-8d1f-14b288730c80%2FAction+URL+URI+Traning.pdf