Send call recordings filename back to web

I have a soft dialer created in web application using php, js connecting Asterisk 17 using webRTC (wss protocol) for outbound calls. I have couple of issues -

  1. Read environment variable- I have enabled to call recordings to be stored in certain location in Asterisk server using MixMonitor in extension.conf file. I have to create the folder daily and put the recordings in that folder. To do that, I have to set an environment variable & read that variable to pass to MixMonitor. Below is the current excerpt for MixMonitor. Folder to be created daily is as per date. Folder structure is var->www->html->2020->07->24. In today’s folder (24), I have to save the call recordings. How to fetch the envrionment variable to contain the folder path
exten =>_X.,1,MixMonitor(/var/www/html/recordings/2020/07/24/out-${EXTEN}-${STRFTIME(${EPOCH},,%Y%m%d)}-${STRFTIME(${EPOCH},,%H%M%S)}.wav,b)
same =>n,Dial(PJSIP/${EXTEN}@provider)
  1. Send filename back to web (php) - After the call hangup/disconnect, I want to send the recordings filename back to the web (php). How do I do that?

Asterisk is a SIP client in this context.

There is a function (SHELL) that allows shell command to be executed and the standard output to be recovered by the dialplan. Assuming you can quote the $ properly, you could use that. However, you should note that the environment variable will be fixed at the time that Asterisk is started. The latter point is fundamental to environment variables.

Doing something in PHP is outside the scope of the forum.

Thanks @david551. Are you suggesting that if the environment variable value is updated, it will not be reflected until asterisk is started again? IOW, Asterisk will have the value of the env variable when it was started.
For second point, I would like to know if there is a way to add any custom attributes to the BYE response from Asterisk. I am attaching the screenshot of BYE response received in the front end (web) after the call end.

In the response, it has Via:, From:, To:, Call-ID:, CSeq, Reason:, Max-Forwards:, User-Agent:, Content-Length:. Along with this, can I add another name called " filename: " in Asterisk side before sending the response to the web? If yes, where can I do? Bascially any data other than standard Asterisk response, if it can be sent back.

I am using pjsip so I believe the above response is in pjsip header. Can anyone help me add addtional attribute in the header. I tried this but did not work. I am calling mix monitor function to save the recordings in extension.conf file. So can I access pjsip header there?

I believe the only thing that is configurable in the BYE request, without changing the source code and recompiling, is the cause value in the Reason header.

Thanks @david551. This gives me little hope. Firstly, the header is configurable to some extent. Secondly, it can be edited and recompiled, however, there isn’t any documentation for the second part or if there is, then please guide to it. If it’s a quick change that I can try to make and test, I will be happy to do.

Just a quick ‘drive by’ comment…

Referencing ${EPOCH} twice in the same statement can result in different values. For example:

        same = n,verbose(${EPOCH}-${SHELL(sleep 5)}-${EPOCH})



You may want to simplify the expressions you use to create the file name, replacing:

        same = n,verbose(${EXTEN}-${STRFTIME(${EPOCH},,%Y%m%d)}-${STRFTIME(${EPOCH},,%H%M%S)})


        same = n,verbose(${EXTEN}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})

Apologizing in advance if I’m misunderstanding you. I think you are saying ‘environment variable’ when you mean ‘channel variable.’ An environment variable is an operating system process entity. A channel variable is an Asterisk channel entity.

  1. Something like this may be helpful:
        same = n, set(NOW=${EPOCH})
        same = n, set(FILE_PATH=${STRFTIME(${NOW},,/var/www/html/recordings/%Y/%M/%D/)
        same = n, set(FILE_NAME=${EXTEN}-${STRFTIME(${NOW},,%Y%m%d-%H%M%S)})
        same = n, system(mkdir --parents ${FILE_PATH})
        same = n, mixmonitor(${FILE_PATH}/${FILE_NAME},wav,b)
  1. I always thought fiddling with headers was an INVITE kind of thing. Rather than hacking up Asterisk to customize BYE, how about:

a) Storing ${UNIQUEID} and ${FILE_PATH}/${FILE_NAME} in a database.
b) Adding a custom header including ${UNIQUEID}.
c) Modify the client to extract the ${UNIQEID} and read the row from the database.

Thanks @sedwards. I have DB where I am storing the path of the recordings but that is on another server. I ran into issue with differences in timestamp between these 2 servers, so I could not use the Asterisk current timestamp as the recording file name. Hence I was looking for sending this timestamp in the response header. Nevertheless, I changed the approached and now I am using out-YYYYMMDD-Call-ID.wav as the file name as Call-ID is unique for each call (even if it’s same number). I have a minor issue with mixmonitor which stores empty .wav file when the call is not received or rejected by callee. I will check in this forum if somebody has the same issue otherwise, will post a new question. Thanks once again to @david551 @sedwards. Much appreciate your timely inputs.

If properly installed, the timestamps on the machine running Asterisk should be correct to within about 10ms of UTC. Nowadays it should be easy to get your other machines correct to within 20ms, using NTP servers.

Yes @david551 but the delay we found was more than 2 seconds so we could not construct the file name in second server and also could not find a way to send the filename back in the header to overcome that. Theoretically it should be same with difference in ms as you pointed out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.