cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1958
Views
0
Helpful
10
Replies

Macro Editor => Get Phonebook Entry

Hi,

How can macro editor be used to retrieve a number of a phonebook entry (Maybe by xcommand SearchPhonebook)?

I need to be able to get a number of a contact by it's "Name" and use to for calling.

something like:

function findNumber(cName) {
  xapi.command('Phonebook Search',
  {PhonebookType: "Corporate", SearchString: cName, SearchFilter: "People", ContactType: "Contact"});
}

Thanks,

1 Accepted Solution

Accepted Solutions

You can do console.log like what tomas has provided example.

 

The output will show on your macro editor log window.

 

From there, you'll need to figure out how to extract the number and map it to a new function/variable.

View solution in original post

10 Replies 10

So I assume this is not possible.....!

it is possible. its just a little tricky how to get the results from the commands. This is something there could have been more examples of.

 

const xapi = require('xapi');

function callSomeDude(contact){
  console.log(contact);
}

xapi.command('Phonebook Search',
  {PhonebookType: "Local", SearchString: "dude", SearchFilter: "People", ContactType: "Contact"}).then(callSomeDude);

asri.zainal
Level 1
Level 1

I'm curious why are you doing this?

 

Will this macro be used on a Cisco Touch 10 device because contact searching is built-in on the Touch 10 and you don't need to create your own macro for this.

 

I don't see why it's not possible to use macro to achieve this other than maybe a syntax error to your function.

Do you get errors from running this function?

I’m creating a “Call Support” button on the main page.
Instead of hard coding the number inside the Macro I was going to store the number as a local favourite number so in case the support number changes in future we don’t have to update all the macros on all the codecs.
The macro is basically searching for a local phonebook entry named “Help Desk” and it calls its number.
This way if the call number of the support desk changes, client IT can update the number of the favourite entry not the macro.

Can you post the error/output from executing that function?

 

i'll be honest, i'm too lazy to setup a new macro to test so i just ran the xCommand via SSH to test.

 

The output I'm getting is in the form of:

xCommand Phonebook Search PhonebookId: "Corporate" PhonebookType: "Corporate" SearchString: "FirstName" SearchFilter: "People" ContactType: "Contact"

OK
*r PhonebookSearchResult (status=OK):
*r PhonebookSearchResult ResultInfo Offset: 0
*r PhonebookSearchResult ResultInfo Limit: 50
*r PhonebookSearchResult ResultInfo TotalRows: 1
*r PhonebookSearchResult Contact 1 Name: "FirstName LastName"
*r PhonebookSearchResult Contact 1 ContactId: "s_212"
*r PhonebookSearchResult Contact 1 FirstName: "FirstName"
*r PhonebookSearchResult Contact 1 LastName: "LastName"
*r PhonebookSearchResult Contact 1 ContactMethod 1 ContactMethodId: "1"
*r PhonebookSearchResult Contact 1 ContactMethod 1 Number: "XXXXXX"
*r PhonebookSearchResult Contact 1 ContactMethod 2 ContactMethodId: "2"
*r PhonebookSearchResult Contact 1 ContactMethod 2 Number: "XXXXXXXXXX@lync.zoom.us"
** end

And I think what you are trying to achieve is to extract only the number from the results.

 

I'm not great with XAPI but it looks like you need to modify your function to extract just the number from the full output as above.

 

Seems like a lot of work, the more conventional method is just setup your PABX to redirect the call to whoever is supposed to receive the call at the point of time.

Thanks. What I’m trying to understand is How to read this response in macro editor.
I can then parse it and extract the number.

You can do console.log like what tomas has provided example.

 

The output will show on your macro editor log window.

 

From there, you'll need to figure out how to extract the number and map it to a new function/variable.


@MohammadHadizadeh60767 wrote:
Instead of hard coding the number inside the Macro I was going to store the number as a local favourite number so in case the support number changes in future we don’t have to update all the macros on all the codecs.

So, instead of updating a macro on each endpoint, you will instead need to update a local phonebook entry on each of those endpoints... this doesn't seem like it would save much time or effort.

Updating the macros on an endpoint is really simple if you use a tool like CE-Deploy.  (And similar with local phonebook entries if you must do it that way - so you don't need to wait for someone else to update it for you).

Wayne

Please remember to mark helpful responses and to set your question as answered if appropriate.

dboggs
Level 1
Level 1

Ever get the full macro working?  I am able to pull the contact information but I am unable to find the missing piece of DIALING the number found for the contact -

Issue to solve:  Zoom API constantly changes the SIP number each time the unit disconnects and reconnects to the API.  In order for the speed dial to work the unit MUST dial in using the assigned SIP address so it's recognized as a CRC license unit for any meeting.

--------------macro-------

const xapi = require('xapi');

function callZoom(contact){
  console.log(contact);
}

xapi.event.on('UserInterface Extensions Panel Clicked', (event) => {
if (event.PanelId === 'Zoom-Call') {

xapi.command('Phonebook Search',
  {PhonebookType"Local"SearchString"Zoom"SearchFilter"People"ContactType"Contact"}).then(callZoom);
}

});
--------end of macro----
results in console
 
21:08:57Zoom-Call{"Contact":[{"ContactId":"localContactId-1","ContactMethod":[{"CallRate":"1920","CallType":"Video","ContactMethodId":"1","Device":"Video","Number":"0..10000320000112..02.11abcdef@vip2.zoomcrc.com","Protocol":"SIP","id":"1"}],"Name":"Join Zoom Meeting","Tag":"Favorite","id":"1"}],"ResultInfo":{"Limit":"50","Offset":"0","TotalRows":"1"},"status":"OK"}
 
Thoughts?

dboggs
Level 1
Level 1

HERE IS MY FULL WORKING SCRIPT

Create a speed dial on the home screen for a contact in the CE address book.

Issue - Zoom API constantly changes the uri for the Zoom contact it places in the "Favorites" directory.  We wanted to create a speed dial on the home screen for calling zoom with the uri set by the Zoom API.  Why?  Because if you dial zoom using the uri in the Favorites contact, then zoom recognizes you are calling in from a CRC licensed account and now it does not matter if the host has a zoom crc license or not.  A speed dial on the home screen is wanted so special instructions are not need for users to join a zoom meeting with CRC support and a normal speed dial would not work as the uri changes frequently.

Solution:  Create a macro that searches the phonebook for a "SearchString" matching part of the contact name, find the contact, extract the uri and then dials the uri.

I hope someone finds this useful as I search high and low and banged my head against the wall until I finally got it to work properly.  Enjoy!

----begin code----

const xapi = require('xapi');

 

function callZoom(contact) {

  console.log("Zoom contact found:", contact); // Log the Zoom contact details

// Extract the the contact details

  const sipUri = contact.Contact[0].ContactMethod[0].Number;

  

   if (sipUri && sipUri[1]) {

    const phoneNumber = sipUri[1];

    console.log("Zoom phone number:", sipUri ); // Log the extracted phone number

 

// Use the extracted phone number to initiate a dial command

    xapi.command('dial', { Number: phoneNumber, Protocol: 'Sip'});

  } else {

    console.log("No Zoom phone number found.");

    // Handle the case where the Zoom phone number is not found or does not match the expected pattern

  }

}

// Only run when the home-screen panel-icon called Zoom-Call is clicked 

xapi.event.on('UserInterface Extensions Panel Clicked', (event) => {

if (event.PanelId === 'Zoom-Call') {

 

//Run a search against the Phone book - SearchString is most important here

xapi.command('Phonebook Search',

  {PhonebookType: "Local", SearchString: "Zoom", SearchFilter: "People", ContactType: "Contact"}).then(callZoom);

 

}});

------END OF CODE---------------