Pars a value to a variable in Asterisk

Hi friends,

Need help in getting the values which is in plain text format into a variable of Asterisk.

Below is detailed description:
I am getting result as plain text data from dialogflow voice bot through UNIMRCP Server till asterisk,
i wanted to get this plain text data get played to the caller, when the caller dials from zoiper softphone.
Below is my configuration, i dont know how to get the plain text values parsed into variable.

[context_543]

exten => s,1,Answer
exten => s,2, SynthAndRecog(Please say something, builtin:speech/transcribe , spl=en-US& p=uni2 )

exten => s,3,Goto(synthandrecog-output,s,1)
exten => s,n,Hangup

[synthandrecog-output]
exten => s,1,Verbose(1, status: {RECOG_STATUS}, completion-cause: {RECOG_COMPLETION_CAUSE}, result: {RECOG_RESULT}) exten => s,2,GotoIf(["{RECOG_STATUS}" = "OK"]?3:5) exten => s,3,GotoIf(["{RECOG_COMPLETION_CAUSE}" = "000"]?4:5) exten => s,4,Verbose(1, confidence: {RECOG_CONFIDENCE(0)}, grammar: {RECOG_GRAMMAR(0)}, input: {RECOG_INPUT(0)}, instance: ${RECOG_INSTANCE(0/0)})
exten => s,n,Hangup

Any help appreciated !!

Regards,
AJ

Below is the output i get in asterisk CLI, and the value (<fulfillment_text>Which Room</fulfillment_text>) i wanna get into a asterisk variable
status: OK on PJSIP/6001-00000009

-- Executing [s@app-unimrcp-5:3] Goto("PJSIP/6001-00000009", "synthandrecog-output,s,1") in new stack

-- Goto (synthandrecog-output,s,1)

-- Executing [s@synthandrecog-output:1] Verbose("PJSIP/6001-00000009", "1, status: OK, completion-cause: 000, result: <?xml version="1.0"?><result><interpretation grammar="builtin:speech/transcribe" confidence="1"><instance><query_text>book a room</query_text><action>Training.bot</action><parameters><Location></Location><Time></Time></parameters><fulfillment_text>Which Room</fulfillment_text><fulfillment_messages><text><text>Which Room</text></text></fulfillment_messages><output_contexts><name>projects/test</name><lifespan_count>2</lifespan_count><parameters><Location></Location><Time_original></Time_original><Time></Time><Location_original></Location_original></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>2</lifespan_count><parameters><Location_original></Location_original><Location></Location><Time_original></Time_original><Time></Time></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>1</lifespan_count><parameters><Location></Location><Time_original></Time_original><Time></Time><Location_original></Location_original></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>1</lifespan_count><parameters><no_match>0</no_match><no_input>0</no_input><Time></Time><Location_original></Location_original><Location></Location><Time_original></Time_original></parameters></output_contexts><intent><name>projects/test</name><display_name>Training.Bot</display_name></intent><intent_detection_confidence>1</intent_detection_confidence><language_code>en</language_code><output_audio_uri>http://localhost/utterances/umsgdf-3115398f90be4428-1001.wav</output_audio_uri></instance><input mode="speech">book a room</input></interpretation></result>") in new stack

status: OK, completion-cause: 000, result: <?xml version="1.0"?><query_text>book a room</query_text>Training.bot<fulfillment_text>Which Room</fulfillment_text><fulfillment_messages>Which Room</fulfillment_messages><output_contexts>projects/test<lifespan_count>2</lifespan_count><Time_original></Time_original><Location_original></Location_original></output_contexts><output_contexts>projects/test<lifespan_count>2</lifespan_count><Location_original></Location_original><Time_original></Time_original></output_contexts><output_contexts>projects/test<lifespan_count>1</lifespan_count><Time_original></Time_original><Location_original></Location_original></output_contexts><output_contexts>projects/test<lifespan_count>1</lifespan_count><no_match>0</no_match><no_input>0</no_input><Location_original></Location_original><Time_original></Time_original></output_contexts>projects/test7<display_name>Training.Bot</display_name><intent_detection_confidence>1</intent_detection_confidence><language_code>en</language_code><output_audio_uri>http://localhost/utterances/umsgdf-3115398f90be4428-1001.wav</output_audio_uri>book a room

-- Executing [s@synthandrecog-output:2] GotoIf("PJSIP/6001-00000009", "1?3:5") in new stack

-- Goto (synthandrecog-output,s,3)

-- Executing [s@synthandrecog-output:3] GotoIf("PJSIP/6001-00000009", "1?4:5") in new stack

-- Goto (synthandrecog-output,s,4)

-- Executing [s@synthandrecog-output:4] Verbose("PJSIP/6001-00000009", "1, confidence: 1.00, grammar: builtin:speech/transcribe, input: book a room, instance: <query_text>book a room</query_text><action>Training.bot</action><parameters><Location/><Time/></parameters><fulfillment_text>Which Room</fulfillment_text><fulfillment_messages><text><text>Which Room</text></text></fulfillment_messages><output_contexts><name>projects/test</name><lifespan_count>2</lifespan_count><parameters><Location/><Time_original/><Time/><Location_original/></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>2</lifespan_count><parameters><Location_original/><Location/><Time_original/><Time/></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>1</lifespan_count><parameters><Location/><Time_original/><Time/><Location_original/></parameters></output_contexts><output_contexts><name>projects/test</name><lifespan_count>1</lifespan_count><parameters><no_match>0</no_match><no_input>0</no_input><Time/><Location_original/><Location/><Time_original/></parameters></output_contexts><intent><name>projects/test</name><display_name>Training.Bot</display_name></intent><intent_detection_confidence>1</intent_detection_confidence><language_code>en</language_code><output_audio_uri>http://localhost/utterances/umsgdf-3115398f90be4428-1001.wav</output_audio_uri>") in new stack

confidence: 1.00, grammar: builtin:speech/transcribe, input: book a room, instance: <query_text>book a room</query_text>Training.bot<fulfillment_text>Which Room</fulfillment_text><fulfillment_messages>Which Room</fulfillment_messages><output_contexts>projects/test<lifespan_count>2</lifespan_count><Time_original/><Location_original/></output_contexts><output_contexts>projects/test<lifespan_count>2</lifespan_count><Location_original/><Time_original/></output_contexts><output_contexts>projects/test<lifespan_count>1</lifespan_count><Time_original/><Location_original/></output_contexts><output_contexts>projects/test<lifespan_count>1</lifespan_count><no_match>0</no_match><no_input>0</no_input><Location_original/><Time_original/></output_contexts>projects/test<display_name>Training.Bot</display_name><intent_detection_confidence>1</intent_detection_confidence><language_code>en</language_code><output_audio_uri>http://localhost/utterances/umsgdf-3115398f90be4428-1001.wav</output_audio_uri>

-- Executing [s@synthandrecog-output:5] Hangup("PJSIP/6001-00000009", "") in new stack

== Spawn extension (synthandrecog-output, s, 5) exited non-zero on ‘PJSIP/6001-00000009’

Please use ‘preformatted text’ tags so your snippets don’t get mangled by the web site.

Assuming I read your post correctly. You want to parse out a tag from an XML blob.

(Disclaimer – I’m heavily biased against doing complex stuff in dialplan…)

I’m sure you can find some magic combination of string manipulation functions that will extract the piece of text you’re interested in. But I wouldn’t. It will be fragile and will break when you least expect it.

Personally, I would write an AGI, in a language you know, that has an XML parsing library. I’d make it really generic, something that would parse the passed XML and return the content of the specified tag as a channel variable named for the tag. Also, I’d use getopt_long() so the arguments can be passed and parsed consistently. And syslog() so you can log stuff like debugging output in a consistent place. For example:

same = n,        agi(parse-xml, --debug, --tag=fulfillment_text, --xml="${RECOG_STATUS}")
same = n,        verbose(1, The status of the parse request is ${parse-xml-status})
same = n,        verbose(1, The fulfilment text is ${fulfilment_text})

If the oput is an XML you can use a php function

$xml simplexml_load_file("$feed");

foreach ($xml->channel->item as $item){
code here
}

and then using AGI set variable method return the value back to Asterisk

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