Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Web Interaction Json Content

Discussion in 'CRM / Helpdesk / App Integration' started by maatata, Apr 8, 2014.

Thread Status:
Not open for further replies.
  1. maatata

    Joined:
    Apr 8, 2014
    Messages:
    7
    Likes Received:
    0
    Hi,

    I have already linked my call flow to our php website and it all works ok.

    My only issue is in some responses from our web server I need to get a javascript array which has an array of data in it.
    It won't be a plain text.

    Here is an example of one of the responses I need to get and use in the call flow:

    {"Associates":[{"main_id":"123456","id":"123456","client":"123456","name":"Mr M B"}],"responseHash":"0.76736000.1396951869.82334094"}

    What I need to be able to do is to have access to each single key in this Json query.
    For example in the call flow I need to access name individually and using it in the future steps.

    I am also able to get the respond in php array format like follow:

    Array
    (
    [Associates] => Array
    (
    [0] => Array
    (
    [main_id] => 123456
    [id] => 123456
    [client] => 123456
    [name] => Mr M B
    )

    )
    [responseHash] => 0.76736000.1396951869.82334094
    )

    even if there is a way to work with php array that would be useful for me as well but I assume the 3CX VAD works with Javascript Expressions mostly and won't understand php at all.

    Would it be possible please to help me how to work with Json and Javascript arrays in the 3CX Voice Application ?

    That would be much appreciated if you could help please.

    Thanks
     
  2. VAD_Support

    VAD_Support Active Member

    Joined:
    Aug 6, 2009
    Messages:
    690
    Likes Received:
    0
    Hi there,

    I think you can use the javascript "eval" function to convert the string returned by your web service into a javascript object. Then you can check its properties as usual.

    Hope it helps.
     
  3. maatata

    Joined:
    Apr 8, 2014
    Messages:
    7
    Likes Received:
    0
    Hi there,

    Thank you very much for your quick reply that helps a lot.

    Would you please explain how I can do that through 3CX VAD?

    Can I do that within the application or should I do it out of the VAD please?

    If you could give me an example of how to do it with screenshot maybe please, that would be so much appreciated.

    Thanks a lot for your quick reply.
     
  4. maatata

    Joined:
    Apr 8, 2014
    Messages:
    7
    Likes Received:
    0
    Hi,

    I did try to use Both Eval and JSON.parse but non worked right.

    It doesn't pass the data and it hangs up the call when it gets to that stage

    Would you please help and explain a bit more.

    Thanks a lot.
     
  5. VAD_Support

    VAD_Support Active Member

    Joined:
    Aug 6, 2009
    Messages:
    690
    Likes Received:
    0
    Hi there!

    In first place, you need to create a javascript function in order to store the results into a variable, for example:

    Code:
    function storeVariable(objectString)
    {
      application.myVariable = eval(objectString);
    }
    
    Put the code above into a .js file.

    Then call that function from the VAD using an "External Code Execution" component. You need to configure it to call a javascript function, and select the js file created before.

    Then you can use that variable whenever you need, for example:
    application.myVariable.MyProperty

    The above expression can be used for example in a Variable Assignment component to set that value to some other variable, in a Database Access component to send that info to a database, etc...

    Hope the information helps.
     
  6. maatata

    Joined:
    Apr 8, 2014
    Messages:
    7
    Likes Received:
    0
    Hi There,

    Thanks for your reply and sorry for my late reply. Some how the forum removed my account and my topic which stopped me from replying to you.

    I have done what you said.

    I have created a function in a js file and added a line to it to return the myVariable after doing eval. I called it using "External Code Execution" and after that I added "Variable Assignment" to assign the returned result from the function to a variable called SearchedEmployeeDetails in the call flow.

    I then added a prompt playback after all of these components and selected to be text to speech.

    In the text field I typed in callflow$.SearchedEmployeeDetails.Associates.name

    As soon as the call gets to that stage it hangs up.

    Is there any way I can fix this issue or at least is there any way in VAD to actually see what is happening in the background while the call is in process. For example to see what the output of each component is step by step and be able to pause and find the issue.


    If you could help me please to be able to have access to "name" in the array that would be so much appreciated.

    Here is my JsonStringToVariable.js file which is placed in the library folder:

    Code:
    function storeVariable()
    {
    	var objectString = '{"Associates":[{"main_id":"123456","id":"123456","client":"123456","name":"Mr M B"}],"responseHash":"0.76736000.1396951869.82334094"}';
    	var myVariable = eval('('+objectString+')');
    	return myVariable;
    }

    Here is a screenshot of the External Code Execution settings


    Here is a screenshot of the Variable Assignment settings


    Here is a screenshot of the Prompt Playback settings
     

    Attached Files:

  7. VAD_Support

    VAD_Support Active Member

    Joined:
    Aug 6, 2009
    Messages:
    690
    Likes Received:
    0
    Please take a look at this article:
    http://www.3cx.com/blog/docs/troubleshooting-vad-applications/

    In this case, pretty sure the problem is happening in client side code (javascript), in that case the error detail will appear into the 3CXIvrServer.log or 3CXIvrServer.trace.log files.

    Can you check those files? You can also share the content with me so I take a look.

    Thanks.
     
  8. maatata

    Joined:
    Apr 8, 2014
    Messages:
    7
    Likes Received:
    0
    Thanks for your reply.

    I have attached both 3CXIverServer.log and 3CXIverServer.trace.log for the call I made to test.

    Please have a look at the attached files.

    Here is the 3CXIvrServer.log for the call I made to test:


    Here is the 3CXIvrServer.trace.log for the call I made to test:



    So sorry to trouble you and thanks a lot for your help.
     

    Attached Files:

Thread Status:
Not open for further replies.