API Nummernabfrage

Hallo,

ich habe es mittels diesem Fred geschafft eine Nummernabfrage im FlexPanel anzuzeigen. :smiley:

Wie gehe ich vor wenn ich diese Info auch auf dem Snom Display haben möchte ?

Besten Dank und Gruss Nada

Hallo,

bei welchem Dienst gleichst Du die Nummer ab? Bei dem gennanten Schweizer Dienst?
Ich suche nämlich was für deutsche Nummern…
Würdest Du den Code zur Verfügung stellen?

Gruss
Bjoern

Hi all,

It’s possible to do that using asterisk AGI. I wrote one small dial plan script which calls AGI.


#perform search only if name is not set
exten => s,1,GotoIf($ "${CALLERID(name)}" != "" ] ?skip)
#you can use CALLERID(num) instead of MDC_CALLER_NUM_INTERNAT if you dont want full number
#invoke AGI 
same => n,AGI(agi_your_script.php,${MDC_CALLER_NUM_INTERNAT})
#check execution result
same => n,GoToIf($ "${AGISTATUS}" = "FAILURE" ]?s-failed,1)
#AGI php script should set variable HTTP_CALLER_ID if matching result is found
same => n,ExecIf($ "${HTTP_CALLER_ID}" != "" ]?Verbose(1,"${HTTP_CALLER_ID}")
same => n,ExecIf($ "${HTTP_CALLER_ID}" != "" ]?Set(CALLERID(name)=${HTTP_CALLER_ID}))
same => n,Return()
same => n(skip),Return()

You should put your custom script agi_your_script.php in /etc/asterisk/agi with proper owner and privileges. Script should invoke any REST API and put result back in variable HTTP_CALLER_ID


SET VARIABLE HTTP_CALLER_ID "pascom Netzwerktechnik"


If you need a help in writing the php script you can contact our Support team. Also you can share your work with others here. I would like to see your result there and I would be pleased to contribute in writing the script.

Kind regards,
Stefan

Hi all,

Please take a look on our github.

Kind regards,
Stefan

Hallo Stefan,

gerne möchte ich das Script einbinden, erhalte aber in der Web-ui folgende Fehlermeldung :
“Das Feld Skriptinhalt (030scr_inhalt) darf nicht leer sein”

Ich habe ein neues Dialplan-script erstellt mit dem Kontext “sub_pre-main”.
Unter script habe ich den Inhalt von def_agi_rest_phonebook eingefügt.

Danke Nada

Hi Nada,

Unfortunately you are affected by already known bug in version 7.12.01. In your version it’s not possible to create any kind of the script. It will be fixed in the version 7.12.02.

Kind regards,
Stefan

Ok,

Danke für die schnelle Antwort !

Wann kommt die 7.12.02

:rolleyes:

Hab die 7.12.02 nun installiert.

das Script lässt sich installieren , es funktioniert bei mir aber nicht .

Der externe Anruf kommt auf eine Rufgruppe.
Anzeigetext ist : ${CALLERID(name)}
Extern vorher :
Typ : Skript
Bedingung : keine
Name : telsearch (scriptname)
Ausdruck : s,1

wo könnte ich nach dem Problem suchen ?

ich komm nicht weiter …
lässt sich das script auch von “hand” auslösen ?

Hi Nada,

Please first follow the steps explained on github.

Step 1. Create dialplan script in the mobydick web-ui like:


Step 2. Check the path of the .php script. Did you provide the REST_API_KEY?
Step 3-4-5. Check the php file owner and permissions.
Step 6. If you want to use this feature for Team calls you can try:


Please try to make this scenario working and after that you can try with more complex examples. In my example you don’t need to change sub_pre-main.

Kind regards,
Stefan

Hallo Stefan,

vielen Dank für deine Anleitung !
Ich habe alle Schritte befolgt.

Bei mir klappt es aber leider “noch” nicht…

Die rechte des php Sripts stimmen :


Ein Anruf von 0041796xxxxxx an die Rufgruppe 98 sieht so aus :

– Executing [s@sub_defcall:6] Return(“SIP/mdc_trunk_conf-1-00000071”, “”) in new stack
– Executing [98@main:4] Gosub(“SIP/mdc_trunk_conf-1-00000071”, “sub_pre-main,s,1”) in new stack
– Executing [s@sub_pre-main:1] GotoIf(“SIP/mdc_trunk_conf-1-00000071”, “0 ?skip”) in new stack
– Executing [s@sub_pre-main:2] AGI(“SIP/mdc_trunk_conf-1-00000071”, “agi_rest_phonebook.php,0041796xxxxxx”) in new stack
– Launched AGI Script /etc/asterisk/agi/agi_rest_phonebook.php
– <SIP/mdc_trunk_conf-1-00000071>AGI Script agi_rest_phonebook.php completed, returning 0
– Executing [s@sub_pre-main:3] GotoIf(“SIP/mdc_trunk_conf-1-00000071”, “1?skip”) in new stack
– Goto (sub_pre-main,s,7)
– Executing [s@sub_pre-main:7] Return(“SIP/mdc_trunk_conf-1-00000071”, “”) in new stack
– Executing [98@main:5] Goto(“SIP/mdc_trunk_conf-1-00000071”, “mdc_distribute,98,1”) in new stack
– Goto (mdc_distribute,98,1)

Das script wird aufgerufen aber im Telefon wird nur die Nummer angezeigt.
Im Felxpanel wird der Name angezeigt.

Hallo Nada,

def_agi_rest_phonebook is invoked on the wrong place. You still have code in the pre_main. Did you set your queue pre action like in the step 6?

Kind regards,
Stefan

ups , da war ein Eintrag zuviel im Dialplan …

nun die Ausgabe bei einem Anruf auf die Rufgruppe 98

– Goto (mdc_team-3,98-dial,1)
– Executing [98-dial@mdc_team-3:1] Set(“SIP/mdc_trunk_conf-1-000000aa”, “__MDC_EXTEN=98”) in new stack
– Executing [98-dial@mdc_team-3:2] Gosub(“SIP/mdc_trunk_conf-1-000000aa”, “sub_prefix-98,ext,1”) in new stack
– Executing [ext@sub_prefix-98:1] Gosub(“SIP/mdc_trunk_conf-1-000000aa”, “def_agi_rest_phonebook,s,1”) in new stack
– Executing [s@def_agi_rest_phonebook:1] GotoIf(“SIP/mdc_trunk_conf-1-000000aa”, “0 ?skip”) in new stack
– Executing [s@def_agi_rest_phonebook:2] AGI(“SIP/mdc_trunk_conf-1-000000aa”, “agi_rest_phonebook.php,0041796xxxxxx”) in new stack
– Launched AGI Script /etc/asterisk/agi/agi_rest_phonebook.php
– <SIP/mdc_trunk_conf-1-000000aa>AGI Script agi_rest_phonebook.php completed, returning 0
– Executing [s@def_agi_rest_phonebook:3] GotoIf(“SIP/mdc_trunk_conf-1-000000aa”, “1?skip”) in new stack
– Goto (def_agi_rest_phonebook,s,7)
– Executing [s@def_agi_rest_phonebook:7] Return(“SIP/mdc_trunk_conf-1-000000aa”, “”) in new stack

ok, now it looks better. agi_rest_phonebook.php does not return a valid result. Did you create the API key on tel.search.ch and put it in the .php script? Also check if the caller number exists in their dictionary.

Kind regards,
Stefan

API key ist eingefügt und funktioniert … (Flexpanel)

0041796xxxxxx ist im Directory von tel.search eingetragen .

Do you have Internet access from mobydick? Could you ping tel.search.ch?

You can also try to test the script so you can add the following code after the line $phonenumber = $argv[1];

pushVariable(‘HTTP_CALLER_ID’, ‘hello world’);
fclose( STDIN );
fclose( STDOUT );
fclose( STDERR );
exit( 0 );

Could you ping tel.search.ch?

yes

Could you ping tel.search.ch?

yes

obigen Code hab ich eingefügt :

– Goto (mdc_team-3,98-dial,1)
– Executing [98-dial@mdc_team-3:1] Set(“SIP/mdc_trunk_conf-1-00000000”, “__MDC_EXTEN=98”) in new stack
– Executing [98-dial@mdc_team-3:2] Gosub(“SIP/mdc_trunk_conf-1-00000000”, “sub_prefix-98,ext,1”) in new stack
– Executing [ext@sub_prefix-98:1] Gosub(“SIP/mdc_trunk_conf-1-00000000”, “def_agi_rest_phonebook,s,1”) in new stack
– Executing [s@def_agi_rest_phonebook:1] GotoIf(“SIP/mdc_trunk_conf-1-00000000”, “0 ?skip”) in new stack
– Executing [s@def_agi_rest_phonebook:2] AGI(“SIP/mdc_trunk_conf-1-00000000”, “agi_rest_phonebook.php,0041796xxxxxx”) in new stack
– Launched AGI Script /etc/asterisk/agi/agi_rest_phonebook.php
– <SIP/mdc_trunk_conf-1-00000000>AGI Script agi_rest_phonebook.php completed, returning 0
– Executing [s@def_agi_rest_phonebook:3] GotoIf(“SIP/mdc_trunk_conf-1-00000000”, “1?skip”) in new stack
– Goto (def_agi_rest_phonebook,s,7)
– Executing [s@def_agi_rest_phonebook:7] Return(“SIP/mdc_trunk_conf-1-00000000”, “”) in new stack
– Executing [ext@sub_prefix-98:2] Return(“SIP/mdc_trunk_conf-1-00000000”, “”) in new stack
– Executing [98-dial@mdc_team-3:3] Gosub(“SIP/mdc_trunk_conf-1-00000000”, “sub_main-98,ext,1”) in new stack
– Executing [ext@sub_main-98:1] Set(“SIP/mdc_trunk_conf-1-00000000”, “CALLERID(name)=”) in new stack

“hello world” wird im Snom nicht angezeigt …

Could you post here the content of your .php script?


#!/usr/bin/php5 -q
<?php
require_once '/var/www/mobydickcmd/cmn/vendor/phphttpclient/httpful.phar';

$REST_API_KEY = 'your_rest_api_key';

/**
 * this AGI executs an REST request
 * @param $arg1 uri - URI, welche gerufen werden soll
 */
ob_implicit_flush( false );
set_time_limit( 10 );
error_reporting(0);
define ('__DEBUG__', true);

// create file handles if needed
if ( !defined( 'STDIN' ) )
    define( 'STDIN', fopen( 'php://stdin', 'r' ) );
if ( !defined( 'STDOUT' ) )
    define( 'STDOUT', fopen( 'php://stdout', 'w' ) );
if ( !defined( 'STDERR' ) )
    define( 'STDERR', fopen( 'php://stderr', 'w' ) );

// URI
if ( empty( $argv 1 ] ) ) {
    pushVariable( 'HASH(AGI_REST_PHONEBOOK,ERRNO)', 255 );
    pushVariable( 'HASH(AGI_REST_PHONEBOOK,ERRMSG)', 'no phonenumber' );
    fclose( STDIN );
    fclose( STDOUT );
    fclose( STDERR );
    exit( 1 );
}
$phonenumber = $argv 1 ];


/** test */
pushVariable('HTTP_CALLER_ID', 'hello world');
fclose( STDIN );
fclose( STDOUT );
fclose( STDERR );
exit( 0 );
***************


$uri = "http://tel.search.ch/api/?" . http_build_query(array('was' => $phonenumber, 'key' => $REST_API_KEY));
/** @var httpful\Response $response */
$response = \Httpful\Request::get($uri)
    ->sendsAndExpects('application/atom+xml')
    ->autoParse(false)
    ->send();

if ($response->hasErrors()) {
    pushVariable( 'HASH(AGI_REST_PHONEBOOK,ERRNO)', 255 );
    pushVariable( 'HASH(AGI_REST_PHONEBOOK,ERRMSG)', 'rest error' );
    fclose( STDIN );
    fclose( STDOUT );
    fclose( STDERR );
    exit( 1 );
}
$xml = simplexml_load_string($response->body, "SimpleXMLElement", 0, "", true);
$name = $xml->entry[0]->title;
if($name) {
    pushVariable('HTTP_CALLER_ID', $name);
}
fclose( STDIN );
fclose( STDOUT );
fclose( STDERR );
exit( 0 );

/**
 * create the right output to set a channel variable
 * @param $name
 * @param $value
 */
function pushVariable( $name, $value )
{
    fwrite( STDOUT, "SET VARIABLE " . trim( $name ) . " \"" . trim( $value ) . "\" 
" );
    fflush( STDOUT );
}