AGI

pyvr

{‘agi_callerid’ : ‘mars.putland.int’,
‘agi_channel’ : ‘IAX[kputland@kputland]/119’, ‘agi_context’ : ‘default’, ‘agi_dnid’ : ‘1000’, ‘agi_enhanced’ : ‘0.0’, ‘agi_extension’: ‘1000’, ‘agi_language’ : ‘en’, ‘agi_priority’ : ‘1’, ‘agi_rdnis’ : ‘’, ‘agi_request’ : ‘pyst’, ‘agi_type’ : ‘IAX’}

Specification

class asterisk.agi.AGI(stdin=<open file '<stdin>', mode 'r'>, stdout=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>)[source]

This class encapsulates communication between Asterisk an a python script. It handles encoding commands to Asterisk and parsing responses from Asterisk.

answer()[source]

agi.answer() –> None Answer channel if not already in answer state.

appexec(application, options='')[source]

Executes <application> with given <options>. Returns whatever the application returns, or -2 on failure to find application

channel_status(channel='')[source]

agi.channel_status(channel=’‘) –> int Returns the status of the specified channel. If no channel name is given the returns the status of the current channel.

Return values: 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 interrupted by the given digits, if any. escape_digits is a string ‘12345’ or a list of ints [1,2,3,4,5] or strings [‘1’,‘2’,‘3’] or mixed [1,‘2’,3,‘4’] If sample offset is provided then the audio will seek to sample offset before play starts. Returns digit if one was pressed. Throws AGIError if the channel was disconnected. Remember, the file extension must not be included in the filename.

database_del(family, key)[source]

agi.database_del(family, key) –> None Deletes an entry in the Asterisk database for a given family and key.

database_deltree(family, key='')[source]

agi.database_deltree(family, key=’‘) –> None Deletes a family or specific keytree with in a family in the Asterisk database.

database_get(family, key)[source]

agi.database_get(family, key) –> str Retrieves an entry in the Asterisk database for a given family and key. Returns 0 if <key> is not set. Returns 1 if <key> is set and returns the variable in parenthesis example return code: 200 result=1 (testvariable)

database_put(family, key, value)[source]

agi.database_put(family, key, value) –> None Adds or updates an entry in the Asterisk database for a given family, key, and value.

exec_command(command, *args)[source]

Send an arbitrary asterisk command with args (even not AGI commands)

get_data(filename, timeout=2000, max_digits=255)[source]

agi.get_data(filename, timeout=DEFAULT_TIMEOUT, max_digits=255) –> digits Stream the given file and receive dialed digits

get_full_variable(name, channel=None)[source]

Get a channel variable.

This function returns the value of the indicated channel variable. If the variable is not set, an empty string is returned.

get_option(filename, escape_digits='', timeout=0)[source]

agi.get_option(filename, escape_digits=’‘, timeout=0) –> digit Send the given file, allowing playback to be interrupted by the given digits, if any. escape_digits is a string ‘12345’ or a list of ints [1,2,3,4,5] or strings [‘1’,‘2’,‘3’] or mixed [1,‘2’,3,‘4’] Returns digit if one was pressed. Throws AGIError if the channel was disconnected. Remember, the file extension must not be included in the filename.

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.

This function returns the value of the indicated channel variable. If the variable is not set, an empty string is returned.

hangup(channel='')[source]

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

noop()[source]

agi.noop() –> None Does nothing

receive_char(timeout=2000)[source]

agi.receive_char(timeout=DEFAULT_TIMEOUT) –> chr Receives a character of text on a channel. Specify timeout to be the maximum time to wait for input in milliseconds, or 0 for infinite. Most channels do not support the reception of text.

record_file(filename, format='gsm', escape_digits='#', timeout=20000, offset=0, beep='beep', silence=0)[source]

agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep=’beep’, silence=0) –> None Record to a file until a given dtmf digit in the sequence is received. Returns ‘-1’ on hangup or error. The format will specify what kind of file will be recorded. The <timeout> is the maximum record time in milliseconds, or ‘-1’ for no <timeout>. <offset samples> is optional, and, if provided, will seek to the offset without exceeding the end of the file. <silence> is the number of seconds of silence allowed before the function returns despite the lack of dtmf digits or reaching <timeout>. <silence> value must be preceded by ‘s=’ and is also optional.

say_alpha(characters, escape_digits='')[source]

agi.say_alpha(string, escape_digits=’‘) –> digit Say a given character string, returning early if any of the given DTMF digits are received on the channel. Throws AGIError on channel failure

say_date(seconds, escape_digits='')[source]

agi.say_date(seconds, escape_digits=’‘) –> digit Say a given date, returning early if any of the given DTMF digits are pressed. The date should be in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00)

say_datetime(seconds, escape_digits='', format='', zone='')[source]

agi.say_datetime(seconds, escape_digits=’‘, format=’‘, zone=’‘) –> digit Say a given date in the format specfied (see voicemail.conf), returning early if any of the given DTMF digits are pressed. The date should be in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00).

say_digits(digits, escape_digits='')[source]

agi.say_digits(digits, escape_digits=’‘) –> digit Say a given digit string, returning early if any of the given DTMF digits are received on the channel. Throws AGIError on channel failure

say_number(number, escape_digits='')[source]

agi.say_number(number, escape_digits=’‘) –> digit Say a given digit string, returning early if any of the given DTMF digits are received on the channel. Throws AGIError on channel failure

say_phonetic(characters, escape_digits='')[source]

agi.say_phonetic(string, escape_digits=’‘) –> digit Phonetically say a given character string, returning early if any of the given DTMF digits are received on the channel. Throws AGIError on channel failure

say_time(seconds, escape_digits='')[source]

agi.say_time(seconds, escape_digits=’‘) –> digit Say a given time, returning early if any of the given DTMF digits are pressed. The time should be in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00)

send_command(command, *args)[source]

Send a command to Asterisk

send_image(filename)[source]

agi.send_image(filename) –> None Sends the given image on a channel. Most channels do not support the transmission of images. Image names should not include extensions. Throws AGIError on channel failure

send_text(text='')[source]

agi.send_text(text=’‘) –> None Sends the given text on a channel. Most channels do not support the transmission of text. Throws AGIError on error/hangup

set_autohangup(secs)[source]

agi.set_autohangup(secs) –> None Cause the channel to automatically hangup at <secs> 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.

set_callerid(number)[source]

agi.set_callerid(number) –> None Changes the callerid of the current channel.

set_context(context)[source]

Sets the context for continuation upon exiting the application. No error appears to be produced. Does not set exten or priority Use at your own risk. Ensure that you specify a valid context.

set_extension(extension)[source]

Sets the extension for continuation upon exiting the application. No error appears to be produced. Does not set context or priority Use at your own risk. Ensure that you specify a valid extension.

set_priority(priority)[source]

Sets the priority for continuation upon exiting the application. No error appears to be produced. Does not set exten or context Use at your own risk. Ensure that you specify a valid priority.

set_variable(name, value)[source]

Set a channel variable.

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

agi.stream_file(filename, escape_digits=’‘, sample_offset=0) –> digit Send the given file, allowing playback to be interrupted by the given digits, if any. escape_digits is a string ‘12345’ or a list of ints [1,2,3,4,5] or strings [‘1’,‘2’,‘3’] or mixed [1,‘2’,3,‘4’] If sample offset is provided then the audio will seek to sample offset before play starts. Returns digit if one was pressed. Throws AGIError if the channel was disconnected. Remember, the file extension must not be included in the filename.

tdd_mode(mode='off')[source]

agi.tdd_mode(mode=’on’|’off’) –> None Enable/Disable TDD transmission/reception on a channel. Throws AGIAppError if channel is not TDD-capable.

test_hangup()[source]

This function throws AGIHangup if we have recieved a SIGHUP

verbose(message, level=1)[source]

agi.verbose(message=’‘, level=1) –> None Sends <message> to the console via verbose message system. <level> is the the verbose level (1-4)

wait_for_digit(timeout=2000)[source]

agi.wait_for_digit(timeout=DEFAULT_TIMEOUT) –> digit Waits for up to ‘timeout’ milliseconds for a channel to receive a DTMF digit. Returns digit dialed Throws AGIError on channel falure

exception asterisk.agi.AGIAppError[source]
exception asterisk.agi.AGIDBError[source]
exception asterisk.agi.AGIError[source]
exception asterisk.agi.AGIException[source]
exception asterisk.agi.AGIHangup[source]
exception asterisk.agi.AGIInvalidCommand[source]
exception asterisk.agi.AGIResultHangup[source]
exception asterisk.agi.AGISIGHUPHangup[source]
exception asterisk.agi.AGISIGPIPEHangup[source]
exception asterisk.agi.AGIUnknownError[source]
exception asterisk.agi.AGIUsageError[source]