Skip to content

Laboratorio 2

iPERFEX TEAM edited this page Feb 23, 2022 · 13 revisions

En este laboratorio vamos a utilizar algunos comando de AGI como:

AGI Commands

https://wiki.asterisk.org/wiki/display/AST/AGI+Commands

  1. Creamos el directorio
mkdir -p /root/programando-ivrs-en-go-introduccion/code/laboratorio2
  1. Creamos desde el Visual Studio Code el archivo.
code /root/programando-ivrs-en-go-introduccion/code/laboratorio2/laboratorio2.go

Pegamos este código y salvamos.

package main

import (
	"log"
	"os"

	"github.com/CyCoreSystems/agi"
)

var portFastAGI string
var serverMediaURL string

/**
* Get env variables
**/
func goDotEnvVariable(key string) string {
	return os.Getenv(key)
}

func init(){

	portFastAGI = goDotEnvVariable("FASTAGI_PORT")
	if portFastAGI == "" {
		portFastAGI = "8000"
	}

	serverMediaURL = goDotEnvVariable("SERVER_MEDIA")
	if serverMediaURL == "" {
		serverMediaURL = "http://fastagi:8011/"
	}

}

func main() {

	log.Println("FastAGI Server agi://0.0.0.0:" + portFastAGI + " running...")
	agi.Listen(":"+portFastAGI, handler)

}

func handler(a *agi.AGI) {
	defer a.Close()

	a.Verbose(". .: DEMO :.", 1)
	a.Answer()
	a.Set("CHANNEL(language)", "es")
	a.Verbose("PRUEBA 4 - PLAYBACK AUDIO", 1)
	a.StreamFile("tt-monkeys", "#", 1)
	a.Set("__VAR_GLOBAL", a.Variables["agi_arg_1"])
	a.Hangup()

}

Inicializar Código

Vamos a la terminar del contenedor fastagi-dev la cual ya tenemos abierta por el laboratorio1 Docker Attach Shell fastagi-dev

ls -la
cd laboratorio2
go mod init laboratorio2
go mod tidy
go run laboratorio2

lab2

Nos cambiamos de terminal al contenedor asterisk-iax2 la cual ya tenemos abierta por el laboratorio1 Docker Attach Shell asterisk-iax2

Ejecutamos el comando:

asterisk -rvvvvvvvvvvv

Y luego activamos el debug de agi con el comando agi set debug on dentro de la terminal de Asterisk

voip*CLI> agi set debug on

lab2 asterisk

Realicemos una llamada desde el Zoiper a la extensión 12345 y analicemos la salida.

Salida de Asterisk

bash-5.1# asterisk -rvvvvvvvvvvv
Asterisk 18.2.2, Copyright (C) 1999 - 2018, Digium, Inc. and others.
Created by Mark Spencer <[email protected]>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 18.2.2 currently running on voip (pid = 1)
voip*CLI> agi set debug on
AGI Debugging Enabled
    -- Accepting AUTHENTICATED call from 172.23.0.1:56024:
    --        > requested format = g723,
    --        > requested prefs = (),
    --        > actual format = ulaw,
    --        > host prefs = (ulaw|alaw|gsm),
    --        > priority = mine
    -- Executing [12345@from-internal:1] NoOp("IAX2/100-3741", "DOCKER ASTERISK FASTAGI GO") in new stack
    -- Executing [12345@from-internal:2] AGI("IAX2/100-3741", "agi://fastagi:8000, ivrdemo1,es") in new stack
AGI Tx >> agi_network: yes
<IAX2/100-3741>AGI Tx >> agi_request: agi://fastagi:8000
<IAX2/100-3741>AGI Tx >> agi_channel: IAX2/100-3741
<IAX2/100-3741>AGI Tx >> agi_language: en
<IAX2/100-3741>AGI Tx >> agi_type: IAX2
<IAX2/100-3741>AGI Tx >> agi_uniqueid: 1645648826.0
<IAX2/100-3741>AGI Tx >> agi_version: 18.2.2
<IAX2/100-3741>AGI Tx >> agi_callerid: 100
<IAX2/100-3741>AGI Tx >> agi_calleridname: Test
<IAX2/100-3741>AGI Tx >> agi_callingpres: 1
<IAX2/100-3741>AGI Tx >> agi_callingani2: 0
<IAX2/100-3741>AGI Tx >> agi_callington: 0
<IAX2/100-3741>AGI Tx >> agi_callingtns: 0
<IAX2/100-3741>AGI Tx >> agi_dnid: 12345
<IAX2/100-3741>AGI Tx >> agi_rdnis: unknown
<IAX2/100-3741>AGI Tx >> agi_context: from-internal
<IAX2/100-3741>AGI Tx >> agi_extension: 12345
<IAX2/100-3741>AGI Tx >> agi_priority: 2
<IAX2/100-3741>AGI Tx >> agi_enhanced: 0.0
<IAX2/100-3741>AGI Tx >> agi_accountcode: 
<IAX2/100-3741>AGI Tx >> agi_threadid: 140543549557560
<IAX2/100-3741>AGI Tx >> agi_arg_1:  ivrdemo1
<IAX2/100-3741>AGI Tx >> agi_arg_2: es
<IAX2/100-3741>AGI Tx >> 
<IAX2/100-3741>AGI Rx << VERBOSE ". .: DEMO :." 1
 agi://fastagi:8000, ivrdemo1,es: . .: DEMO :.
<IAX2/100-3741>AGI Tx >> 200 result=1
<IAX2/100-3741>AGI Rx << ANSWER
<IAX2/100-3741>AGI Tx >> 200 result=0
<IAX2/100-3741>AGI Rx << SET VARIABLE CHANNEL(language) es
<IAX2/100-3741>AGI Tx >> 200 result=1
<IAX2/100-3741>AGI Rx << VERBOSE "PRUEBA 4 - PLAYBACK AUDIO" 1
 agi://fastagi:8000, ivrdemo1,es: PRUEBA 4 - PLAYBACK AUDIO
<IAX2/100-3741>AGI Tx >> 200 result=1
<IAX2/100-3741>AGI Rx << STREAM FILE tt-monkeys # 1
    -- <IAX2/100-3741> Playing 'tt-monkeys.slin16' (escape_digits=#) (sample_offset 1) (language 'es')
<IAX2/100-3741>AGI Tx >> 200 result=0 endpos=260352
<IAX2/100-3741>AGI Rx << SET VARIABLE __VAR_GLOBAL ivrdemo1
<IAX2/100-3741>AGI Tx >> 200 result=1
<IAX2/100-3741>AGI Rx << HANGUP
<IAX2/100-3741>AGI Tx >> 200 result=1
<IAX2/100-3741>AGI Tx >> HANGUP
    -- <IAX2/100-3741>AGI Script agi://fastagi:8000 completed, returning 4
<IAX2/100-3741>AGI Tx >> HANGUP
  == Spawn extension (from-internal, 12345, 2) exited non-zero on 'IAX2/100-3741'
    -- Executing [h@from-internal:1] Hangup("IAX2/100-3741", "") in new stack
  == Spawn extension (from-internal, h, 1) exited non-zero on 'IAX2/100-3741'
    -- Hungup 'IAX2/100-3741'
voip*CLI> 
Clone this wiki locally