Integrating Linphone Presence with Asterisk Presence State Module

Hello Asterisk Community!

I hope this post finds you well. I wanted to share my recent exploration into enhancing Asterisk’s capabilities by integrating Linphone’s presence with the Asterisk Presence State module. This setup has proven to be incredibly useful for me, and I thought it would be valuable to share my experience and open up a discussion about this integration.

Objective: My goal was to automatically reflect my Linphone presence on Asterisk using the Presence State module. This allows me to manage my availability seamlessly within the Asterisk environment and provides a convenient way to check my status using the Presence State List command.

I don’t understand this post…

Hello jcolp,
thanks for the reply, i mean to say i have a ipphone with DND feature so i want to impliment my dialplan like if my exten(1001) loged in ipphone is on DND mode than incoming call on 1001 will not receive on 1001 and call is routed to another extension (assume 1002)

To implement a scenario where an incoming call to extension 1001 is redirected to extension 1002 if the Linphone associated with extension 1001 is in “Do Not Disturb” (DND) mode, you can utilize Asterisk’s dialplan and device state feature.

Here’s an example of how you might implement this in your Asterisk dialplan (extensions.conf):

exten => 1001,1,Gosub(checkDND,1)
same => n,Dial(SIP/1001) ; Ring extension 1001 if not in DND
same => n,Hangup()

exten => 1002,1,Dial(SIP/1002) ; Default behavior for extension 1002

exten => 1,1,Set(DND_STATE=${DEVICE_STATE(SIP/1001)})
same => n,GotoIf($[${DND_STATE} = INUSE]?dnd)
same => n,Return()

exten => dnd,1,NoOp(Extension 1001 is in DND mode)
same => n,Return()
In this example:

  • When a call comes in for extension 1001, Asterisk first goes to the checkDND context using the Gosub command.
  • In the checkDND context, it checks the state of extension 1001. If the device is in use (DND mode), it jumps to the dnd extension where you can handle the call accordingly (for example, redirecting it to extension 1002). Otherwise, it returns to the calling context, and the call proceeds to ring extension 1001.

Hello danishhafeez,
A great thanks for reply but i dont want to create dialplan because dialplan or any condition you provide only works when it the presence actually changed in core show hints or presencestate list command i mean to say when my ipphone is on DND mode how will my asterisk know

If your IP phone is on “Do Not Disturb” (DND) mode, the presence state of that phone typically changes to reflect this status. In Asterisk, you can monitor the presence state of extensions using hints.

Hints allow you to monitor the state of an extension, including whether it’s in use, ringing, or in DND mode. When an extension changes its state (e.g., goes into DND mode), Asterisk will update the associated hint, allowing you to trigger actions based on that state change.

so first you have to study about hint and its working

hello danishhafeez,

Thanks for reply. i am not aware of hints but if i uses hints in dialplan than it will work if a call is dialed and than we can set device state but it sounds that we are doing it manually. my question is this that when we turn on DND mode than what asterisk automatically change presence of exten immediately if yes than kindly provide me configurations.

In Asterisk, the presence state of an extension can be automatically updated when the extension’s device changes its state. This can include events like activating or deactivating DND mode on an IP phone. Asterisk can be configured to monitor these state changes and update the presence accordingly.

To configure Asterisk to automatically update presence when DND mode is activated or deactivated, you typically need to ensure that your IP phones are properly configured to send presence state notifications to Asterisk. This usually involves configuring the phones to send SIP NOTIFY messages to Asterisk when their state changes.

  1. Configure Asterisk to Handle Presence: In your Asterisk configuration files (typically extensions.conf), you’ll need to define hints for each extension you want to monitor. Hints allow Asterisk to monitor the state of each extension’s associated device.Example:
exten => 100,hint,SIP/100

This line associates extension 100 with the SIP device 100, allowing Asterisk to monitor its state.
2. Handle Presence State Changes in Dialplan: Once Asterisk detects a change in the presence state of an extension (such as when DND mode is activated), you can use this information to trigger actions in your dialplan. For example, you might route calls differently or send calls directly to voicemail when an extension is in DND mode.Example:

exten => 100,n,GotoIf($[${HINT:100@default} = 'Unavailable']?dnd,1)
exten => 100,n,Dial(SIP/100)
exten => 100,n(dnd),Voicemail(100@default)

In this example, if extension 100 is in the “Unavailable” state (indicating DND mode), the call is sent directly to voicemail. Otherwise, the call is dialed normally.

thanks for the reply danishhafeez,

I configure hint in dialplan

exten => 1001,hint,SIP/1001
exten => 1002,hint,SIP/1002
exten => 1003,hint,SIP/1003

exten => _X.,1,GotoIf($[${HINT:${EXTEN}@default} = ‘Unavailable’]?dnd,1)
exten => _X.,2,Dial(SIP/${EXTEN})
exten => _X.,3(dnd),Voicemail(${EXTEN}@default)
exten => _X.,4,Hangup()

and after core reload

Dpk2*CLI> core show hints

-= Registered Asterisk Dial Plan Hints =-

1000@demo : SIP/1000 State:Unavailable Presence:not_set Watchers 0
1001@demo : SIP/1001 State:Idle Presence:not_set Watchers 0
1001@presence_test : SIP/1001 State:Idle Presence:not_set Watchers 0
1002@presence_test : SIP/1002 State:Idle Presence:not_set Watchers 0
1003@presence_test : SIP/1003 State:Idle Presence:not_set Watchers 0
1234@default : SIP/1234 State:Unavailable Presence:not_set Watchers 0

  • 6 hints registered
    and for testing 1001 is on ipphone , 1002 is on linphone , and 1003 is on zoiper logged in
    check many times after changing presence like DND, busy , offline but
    still all presence:not_set is shows default no any change in it.

Endpoint-side DND is not communicated or stored in Asterisk. It is done on the endpoint and applied when you send a call to it. Anything outside of that is custom development between the endpoint and Asterisk itself.

Using something like a custom extension to toggle DND in Asterisk would have it done Asterisk side instead, using custom dialplan logic.

@danishhafeez I don’t know if you’re using ChatGPT, or AI through something else, but I’ve noticed a lot of your answers aren’t really accurate.

Hello Jcolp,

i understand what you said but in my linphone(soft phone ) when i change my presence than asterisk will show logs mean in somewhere in universe asterisk is notifying what’s going on in soft phone so why we can’t implement that if any log from soft phone received than presence automatically changed according it i am adding some logs when i change my presence from online to DND

To: “1003” sip:1003@
Call-ID: pZl3kEuW90
Max-Forwards: 70
Supported: replaces, outbound, gruu
Event: presence
Content-Type: application/pidf+xml
Content-Length: 564
Expires: 3600
User-Agent: Linphone Desktop/ (Ubuntu 22.04.3 LTS, Qt 5.15.3) LinphoneCore/4.4.21

<?xml version="1.0" encoding="UTF-8"?> closed sip:1003@ -- 2024-02-26T09:56:39Z <-------------> --- (13 headers 16 lines) --- Sending to (NAT)

<— Transmitting (NAT) to —>

That’s not supported by Asterisk. Implementing it would require writing a PJSIP module in C code to understand it, and then finding the best way to integrate it into the Asterisk core and use it in the dialplan.

I had that impression. as well.

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