Donnerstag, 27. April 2023

Teams Presence synchronization for a 3CX on premises

 The recent posts about setting Teams presence and being notified about Teams presence changes are the building blocks to synchronize the presence state between MS Teams and our 3CX PBX both ways.

  • a call on Teams sets the 3CX presence state to "Away" if it was "Available" before
  • if Teams becomes "Available" and 3CX state is "Away" => set 3CX to "Available"
  • a call on 3CX tries to set the Teams presence "Busy" - there is some logic behind the scenes, we can't control about overriding "Offline" and "Away" in Teams which comes in handy in this case

In order to interact with the 3CX PBX there is an inoffical call flow API for v16 which has been adopted by the 3cx-web-api project. Apart from TAPI and CRM integrations this seems to be the only way to react to call states as well as set the presence state.

The API is written in C# using the .Net 5.0 framework since 3CX is a .Net application. It would have been nice to incorporate the presence functionality I coded in Bash into the 3cx-web-api. Unfortunately my coding skills are somewhat basic, especially when it comes to MVC design patterns which are used throughout all Microsoft identity sample projects.

I did manage to extend the 3cx-web-api to handle the notification webhook. That spares the use of the rudimentary webserver+socat of the previous post.

In order to direct traffic to the API I modified the /etc/nginx/sites-enabled/3cxpbx (normally a sym-link) and added an upstream and location setting:

    upstream webapi {
    server {
        location ~ ^/secret-url-teams-presence-notification {
            proxy_pass          http://webapi;

Note: in this setup the path-name is the only "secret", preventing anybody to tamper with your PBX!!!

After building the 3cx-web-api according to the, the StdOut of the program can be used to handle presence changes in a Bash script.

The files from the previous two posts handle the Microsoft communication.

3 Kommentare:

  1. I have attempted to replicate your scripts and i think i have it setup correctly with the MS Teams auth files. When i run the script above it just immediately ends and no looping of the StdOutput takes place. I am running this on the 3cx machine itself on Debian. If you can give me some advice i would appreciate it. I want to do exactly what you describe for my users and i would love to get this working on my 3cx.

    1. Hi HP, could we possibly take this to Github:

      Comments here tend to get messy ;)

  2. Thank you for replying Alexander. I can do that but the issues I seem to be having aren't specifically related to the API, which works well and is able to run properly. I need help to figure out why StdOutput doesn't run when the script above is launched and likely with the MS Teams authentication part too. Okay for me to open an issue at Github on that basis?