Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl & Tropo API

Renee
October 27, 2013

Perl & Tropo API

Mit der Tropo-API der Telekom kann man einiges an Telekommunikation automatisieren - dank Tropo.pm auch aus Perl heraus. Dieser Vortrag gibt einen kleinen Einblick was alles möglich ist...

Renee

October 27, 2013
Tweet

More Decks by Renee

Other Decks in Programming

Transcript

  1. Features • Text2Speech • Spracherkennung • Speech2Text • Anrufmanagement •

    Anrufaufzeichnung • SMS • Telefonanrufe • Telefonkonferenzen • Audio-Dateien abspielen
  2. 2 Wege • TropoScripting – JavaScript, PHP, Ruby, Python, and

    Groovy • Tropo Web-API – Beliebige Sprache, – … da Anwendung auf eigenem Webspace laufen
  3. Das braucht man • Account bei developergarden.com – Kostenlos –

    Gesprächsminuten kosten Geld • Wenn man Anrufe erwartet: – Zugeordnete Telefonnummer
  4. get '/' => sub { shift->render('form'); }; @@ form.html.ep <form

    action="" method="post"> Your phone number (international format, e.g. +4912345678): <input type="text" name="phone" /> <br /> <button type="submit" value="Call me!"> Call me! </button> </form>
  5. post '/' => sub { my $self = shift; my

    $phone = $self->param( 'phone' ); if ( !$phone || !_check_phone( $phone ) ) { return $self->render('form'); } else { my $s = Tropo::RestAPI::Session->new( url => 'https://tropo.developergarden.com/api/', ); my $data = $session->create( token => $token, phone => $phone, ) or $self->app->log->error( $session->err ); } $self->render('call'); };
  6. $VAR1 = { 'session' => { 'userType' => 'NONE', 'parameters'

    => { 'token' => 'your_api_token', 'action' => 'create', 'phone' => '+491772416996' }, 'callId' => undef, 'initialText' => undef, 'timestamp' => '2013-09-06T18:53:20.168Z', 'accountId' => '9183', 'id' => '9884f64erb41e97948083c25980d63683' } };
  7. post '/tropo/' => sub { my $self = shift; my

    $tropo_data = $self->req->json; my $phone = $tropo_data->{session}->{parameters}->{phone}; my $tropo = Tropo->new; $tropo->call( $phone ); $tropo->say( 'activation code is ' . sprintf "%04d", int rand (9999) ); my $data = $tropo->perl; $self->render( json => $data ); };