Answer an incoming call by a sip account programatically using AMI - asterisk

I use asterisk in my project and users login with softphones. I want to grant a person to forward an incoming call to another user's sip account by clicking on a button and answer the call immediately so that the user will be able to start talking with caller.

You need read documentation for you softphones/hardphones. Usualy need add sip header Call-Info: answer-after=0.
So you plan can be
Check if auto-answer/intercom posible with your softphone or hardphone.
Create dialplan which will add header and call
Transfer call to that dialplan using AMI Transfer command
For more info check this:
http://icesupport.ingeniussoftware.com/customer/portal/articles/990030-asterisk-auto-answer-on-originate
http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+Transfer

Related

Pulling only Registration Contact information on Asterisk

I am not using real-time asterisk , But still astdb.sqlite3 contains entries of online peers with Reg.Contact information in SIP/registry/peer. key . I would like to store contact information of all peers as they come online in a separate persistent database. I need this for sending push notifications by fetching deviceID etc information in registration contact .
I tried to pull this information from astdb.sqlite3 but the entries are clearing off as soon as devices go offline .Though I am able to fetch the information with "sip show peer XXXX" in asterisk CLI , It is overburdened to fetch every time like this . Instead I want to save only Regcontact information for all the devices in a database ( without realtime) as the devices come online. The other way I tried to pull the information is using AMI event listener. But with AMI I don't see complete information like contact information It displays only below information
Event: PeerStatus
Privilege: system,all
SequenceNumber: 75
File: manager.c
Line: 1856
Func: manager_default_msg_cb
ChannelType: SIP
Peer: SIP/2030
PeerStatus: Reachable
Can someone suggest a better way to push Only Regcontact information to a database as the devices come online .
There are no mechanism like that in asterisk.
You can use kamailio or write patch similar to this one https://reviewboard.asterisk.org/r/4490/
It sounds like you have dynamic IPs for your endpoints, and you want a way to update a separate DB as soon as a device registers with an IP/port pair.
If you enable the security log, you will see all auth events, including the "SuccessfulAuth" event, which includes the RemoteAddress of the endpoint (including port and protocol).
Here is an example line:
[Jul 21 19:53:45] SECURITY[1342] res_security_log.c: SecurityEvent="SuccessfulAuth",EventTV="2020-07-21T19:53:45.182+0000",Severity="Informational",Service="SIP",EventVersion="1",AccountID="102",SessionID="0x7f41040132c0",LocalAddress="IPV4/UDP/10.0.0.200/5060",RemoteAddress="IPV4/UDP/10.0.0.75/5062",UsingPassword="1"
If all you're looking for is AccountID="102" and RemoteAddress="IPV4/UDP/10.0.0.75/5062", a very fast/cheap way to get it is to enable the security log, and use a script to tail it and update your DB as soon as the event occurs. I like to keep the security log on anyways for utilities like fail2ban. Just make sure your script is able to reopen the file each time it is rotated.
Edit:
By default the log is in /var/log/asterisk. To enable it, edit /etc/asterisk/logger.conf and un-comment (or create) the line under [logfiles] that says security => security.

Freeswitch Guide how to get CDR UUID from client side

My system contain:
- Freeswitch server
- Sip Client: Web using sipjs , mobile react-native using https://github.com/datso/react-native-pjsip to receive call.
My problem is when call done i need to know the uuid of CDR recently add to Postgres DB of that call to attach some info to that call
I try many way but can not success ex: write http request to select into postgres DB, but can not find exactly which uuid because one extension can make many call one time.
Can anyone help me solve this case?
Mark each call with custom variable like callid
Send that to your app via any method, as sipheader, as sip message, using http post etc.
But you also can just search cdr by start date.

asterisk Call ID in sipml5

How do I get asterisk call Id (uniqueid in cdr table) (for instance, 1487150355.465) in sipml5 client.
As far as I looked, I see only
https://www.doubango.org/sipml5/docgen/symbols/SIPml.Session.html#getId
which has (afaic) no relation to asterisk id.
I know I can set additional headers in asterisk and set there call id, but it cannot be done for some organizational reasons.
Thanks.
Asterisk unique channel id(not call id) assigned to channel. By default asterisk not send that via sip or other protocol.
So no, you can't get it without do something on asterisk.

Setting a Dialplan for guests?

I am trying to configure my asterisk to regsiter every user who tries to connect to it, and allow it to establish calls. I have read that I should set "allowguest = yes" in sip.conf.
What about the dialplan in extensions.conf ? What should I add so that all my users could make and recieve calls ? (this is my first questions).
I would go even more precise about the users : is it possible to allow only guests from one precise domain ? If yes please help find how to do it, I will be very thankful.
Guest calls will go to default context which is in general section of sip.conf
[general]
context=some_restricted_access
About dialplan for calls - you need read some book for beginner or install freepbx/other web which do dialplan for you.
No, you can't allow guests from domain. But you can try play with realm= setting or allow access from one ip by using ip-authentification.

Postfix message received hook

I am writing an web-application which needs to receive e-mail messages to users' internal email addresses, let administrators approve them, and then forward to corresponding user's external mailbox.
I have installed and configured postfix for message receiving task. It uses virtual e-mail addresses, and my existing database where user email addresses are stored. Local email storage is maildir and I use postfix's virtual MDA.
Basically, I would like to execute a script every time a new message is received, and for which user (maildir message id would be very helpful too). Then I could read the message from python code (python had a module for maildir messageboxes) and insert it in database.
I can think of three ways to do this:
iterate user maildirs and check
if there are any new messages, but it would be ineffective for large number of users.
use dbmail and then check if there are any new messages in database (this would be quicker, but I'd have to configure everything from scratch). Besides, existing user data tables cannot be used.
write a wrapper around maildrop/virtual to save message in db and in maildir as well, but I'd need a way to check if received message is valid and successfully saved by the real MDA.
Any suggestions appreciated!
In the /etc/aliases file you can specifiy a program which gets executed everytime a user recieves a mail. This program gets the mail on stdin. So you dont have to poll and your program gets run instantly.
In response to my own question, I used postfix content_filter with X flag set in pipe and process receiving address and message manually. Since I didn't need to access messages in maildir, this approach works fine for me.

Resources