Welcome to pyagi’s documentation!

Contents:

Reference:

pyagi

An Asterisk AGI library for humans.

class pyagi.pyagi.AGI[source]

An Asterisk AGI protocol wrapper.

An instance of this class handles command processing and communication between Asterisk and python.

Attr int DEFAULT_TIMEOUT:
 The default timeout (in ms) to use for methods that take a timeout argument.
Attr int DEFAULT_RECORD:
 The default allowed recording time (in ms) to use for methods that take a record time argument.
answer()[source]

Answers channel if not already in answer state.

See: http://www.voip-info.org/wiki/view/answer

Return type:int
Returns:-1 on channel failure, or 0 if successful.
appexec(application, options='')[source]

Executes application with given options.

See: http://www.voip-info.org/wiki/view/exec

Return type:int
Returns:Whatever the application returns, or -2 on failure to find application.

TODO: Rename this application to exec, to comply with AGI standard.

asyncagi_break()[source]

Interrupts expected flow of Async AGI commands and returns control to previous source (typically, the PBX dialplan).

channel_status(channel='')[source]

Returns the status of the specified channel. If no channel name is given then returns the status of the current channel.

See: http://www.voip-info.org/wiki/view/channel+status

Return type:int
Returns:0 - Channel is down and available. 1 - Channel is down, but reserved. 2 - Channel is off hook. 3 - Digits (or equivalent) have been dialed. 4 - Line is ringing. 5 - Remote end is ringing. 6 - Line is up. 7 - Line is busy.
control_stream_file(filename, escape_digits='', skipms=3000, fwd='', rew='', pause='')[source]

Send the given file, allowing playback to be controlled by the given digits, if any. Use double quotes for the digits if you wish none to be permitted.

See: http://www.voip-info.org/wiki/view/control+stream+file

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed, or -1 on error or if the channel was disconnected.
database_del(family, key)[source]

Deletes an entry in the Asterisk database for a given family and key.

See: http://www.voip-info.org/wiki/view/database+del

Return type:int
Returns:1 if successful, 0 otherwise.
database_deltree(family, key='')[source]

Deletes a family or specific keytree within a family in the Asterisk database.

See: http://www.voip-info.org/wiki/view/database+deltree

Return type:int
Returns:1 if successful, 0 otherwise.
database_get(family, key)[source]

Retrieves an entry in the Asterisk database for a given family and key.

See: http://www.voip-info.org/wiki/view/database+get

Return type:str
Returns:The database entry (if one exists), or an empty string.
database_put(family, key, value)[source]

Adds or updates an entry in the Asterisk database for a given family, key, and value.

See: http://www.voip-info.org/wiki/view/database+put

Return type:int
Returns:1 if successful, 0 otherwise.
get_data(filename, timeout=2000, max_digits=255)[source]

Stream the given file, and receive DTMF data.

See: http://www.voip-info.org/wiki/view/get+data

Return type:str
Returns:Digits received from the channel at the other end.
get_full_variable(name, channel=None)[source]

Retrieve a channel variable. Understands complex variable names and builtin variables, unlike get_variable.

See: http://www.voip-info.org/wiki/view/get+full+variable

Return type:str
Returns:The variable, or an empty string if the variable doesn’t exist.
get_option(filename, escape_digits='', timeout=0)[source]

Behaves similar to STREAM FILE but used with a timeout option.

See: http://www.voip-info.org/wiki/view/get+option

get_result(stdin=<open file '<stdin>', mode 'r'>)[source]

Read the result of a command from Asterisk

get_variable(name)[source]

Get a channel variable.

See: http://www.voip-info.org/wiki/view/get+variable

Return type:str
Returns:The variable, or an empty string if the variable isn’t set.
gosub()[source]

Cause the channel to execute the specified dialplan subroutine, returning to the dialplan with execution of a Return().

hangup(channel='')[source]

Hangs up the specified channel. If no channel name is given, hangs up the current channel.

See: http://www.voip-info.org/wiki/view/hangup

noop()[source]

Does nothing.

See: http://www.voip-info.org/wiki/view/noop

receive_char(timeout=2000)[source]

Receives a character of text on a channel. Most channels do not support the reception of text.

See: http://www.voip-info.org/wiki/view/receive+char

Return type:int
Returns:The decimal value of the character if one is received, or 0 if the channel does not support text reception. Returns -1 only on error/hangup.
receive_text()[source]

Receives a string of text on a channel. Most channels do not support the reception of text.

See: http://www.voip-info.org/wiki/view/receive+text

Return type:str
Returns:The string received, or an empty string on failure.
record_file(filename, format='gsm', escape_digits='#', timeout=20000, offset=0, beep='beep')[source]

Record to a file until a given dtmf digit in the sequence is received.

See: http://www.voip-info.org/wiki/view/record+file

Return type:int
Returns:-1 on hangup or error.
say_alpha(characters, escape_digits='')[source]

Say a given character string, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+alpha

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed. Returns -1 on error/hangup.
say_date(seconds, escape_digits='')[source]

Say a given date, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+date

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed or -1 on error/hangup.
say_datetime(seconds, escape_digits='', format='', zone='')[source]

Say a given time, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+datetime

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed or -1 on error/hangup.
say_digits(digits, escape_digits='')[source]

Say a given digit string, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+digits

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed or -1 on error/hangup.
say_number(number, escape_digits='')[source]

Say a given number, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+number

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed or -1 on error/hangup.
say_phonetic(characters, escape_digits='')[source]

Say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+phonetic

Return type:int
Returns:0 if playback completes without a digit pressed, the ASCII numerical value of the digit if one was pressed, or -1 on error/hangup.
say_time(seconds, escape_digits='')[source]

Say a given time, returning early if any of the given DTMF digits are received on the channel.

See: http://www.voip-info.org/wiki/view/say+time

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed or -1 on error/hangup.
send_command(command, *args)[source]

Send a command to Asterisk

send_image(filename)[source]

Sends the given image on a channel. Most channels do not support the transmission of images.

See: http://www.voip-info.org/wiki/view/send+image

Return type:int
Returns:0 if image is sent, or if the channel does not support image transmission. Returns -1 only on error/hangup.

Image names should not include extensions.

send_text(text='')[source]

Sends the given text on a channel. Most channels do not support the transmission of text.

See: http://www.voip-info.org/wiki/view/send+text

Return type:int
Returns:0 if text is sent, or if the channel does not support text transmission. Returns -1 only on error/hangup.
set_autohangup(secs)[source]

Cause the channel to automatically hangup at time seconds in the future. Of course it can be hungup before then as well. Setting to 0 will cause the autohangup feature to be disabled on this channel.

See: http://www.voip-info.org/wiki/view/set+autohangup

set_callerid(number)[source]

Changes the callerid of the current channel.

See: http://www.voip-info.org/wiki/view/set+callerid

set_context(context)[source]

Sets the context for continuation upon exiting the application.

See: http://www.voip-info.org/wiki/view/set+context

set_extension(extension)[source]

Changes the extension for continuation upon exiting the application.

See: http://www.voip-info.org/wiki/view/set+extension

set_music()[source]

Enables/disables the music on hold generator. If class is not specified, then the ‘default’ music on hold class will be used.

See: http://www.voip-info.org/wiki/view/set+music

set_priority(priority)[source]

Changes the priority for continuation upon exiting the application. The priority must be a valid priority or label.

See: http://www.voip-info.org/wiki/view/set+priority

set_variable(name, value)[source]

Sets a variable to the current channel.

See: http://www.voip-info.org/wiki/view/set+variable

speech_activate_grammar()[source]

Activates the specified grammar on the speech object.

speech_create()[source]

Create a speech object to be used by the other Speech AGI commands.

speech_deactivate_grammar()[source]

Deactivates the specified grammar on the speech object.

speech_destroy()[source]

Destroy the speech object created by ‘SPEECH CREATE’.

speech_load_grammar()[source]

Loads the specified grammar as the specified name.

speech_recognize()[source]

Plays back given prompt while listening for speech and dtmf.

speech_set()[source]

Set an engine-specific setting.

speech_unload_grammar()[source]

Unloads the specified grammar.

stream_file(filename, escape_digits='', sample_offset=0)[source]

Send the given file, allowing playback to be interrupted by the given digits, if any.

See: http://www.voip-info.org/wiki/view/stream+file

Return type:int
Returns:0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit if one was pressed, or -1 on error or if the channel was disconnected.
tdd_mode(mode='off')[source]

Enable/disable TDD transmission/reception on a channel.

See: http://www.voip-info.org/wiki/view/tdd+mode

Return type:int
Returns:1 if successful, or 0 if channel is not TDD-capable.
verbose(message, level=1)[source]

Sends message to the console via verbose message system. level is the verbose level (1-4).

See: http://www.voip-info.org/wiki/view/verbose

wait_for_digit(timeout=2000)[source]

Waits up to timeout milliseconds for channel to receive a DTMF digit.

See: http://www.voip-info.org/wiki/view/wait+for+digit

Return type:chr
Returns:-1 on channel failure, 0 if no digit is received in the timeout, or the numerical value of the ASCII of the digit if one is received. Use -1 for the timeout value if you desire the call to block indefinitely.

Indices and tables