POE::Component::Telephony::CTPort - Non-blocking telephony programming in Perl


        use POE qw(Compoent::Telephony::CTPort);
                inline_states => {
                        _start => sub {
                                my $kernel = $_[KERNEL];
                                        alias => 'ctport',
                                        port => 1,
                                $kernel->post(ctport => 'connect');
                        connected => sub {
                                my $kernel = $_[KERNEL];
                                print "connected to ctserver on port 1\n";
                        input => sub {
                                my ($kernel, $in) = @_[KERNEL, ARG0];
                                # all events are sent here, this is a good
                                # spot to use Data::Dumper
                                if ($in->{rly} eq 'ring') {
                                        $kernel->yield(ring => $in);
                        ring => sub {
                                my $kernel = $_[KERNEL];
                                # pick up phone
                                $kernel->post(ctport => 'off_hook');
                                # play beep
                                $kernel->post(ctport => play => 'beep');
                                # record
                                $kernel->post(ctport => record =>
                                        # to this file
                                        # for 15 seconds
                                        # or until they hit #
                                        # or 3 seconds of silence
                                # play it back to them
                                $kernel->post(ctport => play => 'prompt.wav');
                                # play 3 beeps
                                $kernel->post(ctport => play => 'beep beep beep');
                                # hangup
                                $kernel->post(ctport => 'on_hook');
                                # shutdown
                                $kernel->post(ctport => 'disconnect');
                                $kernel->post(ctport => 'shutdown');


This module implements a non blocking perl interface to CTserver, a server that controls voictronix card operation.


You need a voicetronix card, the voictronix driver, and ctserver installed to use this module!



                alias => 'ctport',
                port => 1 

Don't start ctserver yourself, on the first spawn of CTPort, ctserver will be launched in a fork(). To not run ctserver from this module, specify no_ctserver_fork => 1 as a parameter.

You can specify all or none of the parameters:

  • ctserver - the path to the ctserver binary, 'ctserver' is the default (in the path)

  • alias - name to address the component, 'ctport' is the default

  • paths - search paths for the play event, as an array ref: [ '/mnt/cdrom0', '/mnt/cdrom1' ]

  • default_ext - default extension for sound files (default is '.au')

  • reply_to - allows you to specify a different session id to send events to

  • hostname - default is localhost

  • port - a port number from 1 to 4 (1 is default)

  • ignore_dtmf - 1 _or_ 0 (inital setting, used for playing sounds)

  • no_ctserver_fork - 1 _or_ 0 (0 is default)

spawn() returns a reference to the internal session, but do not keep a copy of it. Instead call the ID method and save that:

$heap->{ctport} = POE::Component::Telephony::CTPort->spawn()->ID;

If you spawn more than one CTPort session, change the alias! Like this:

POE::Component::Telephony::CTPort->spawn({ alias => 'ct1' }); POE::Component::Telephony::CTPort->spawn({ alias => 'ct2' }); POE::Component::Telephony::CTPort->spawn({ alias => 'ct3' }); POE::Component::Telephony::CTPort->spawn({ alias => 'ct4' });

This will spawn four sessions and you are ready to tell each one to connect to a different ctserver port. See the 'connect' event.


Any 'blocking' mentioned in this document is only related to the port does not send or receive commands, POE will NOT block for any of these events.

It takes alot of experimenting with this module and ctserver to get a working routine down. My advice is to start off with 1 command, and analize the results and setup your script to watch for those results before sending the next command. Firing off the commands without knowing what is happening doesn't work well. :)

The alias 'ctserver' is used internally for spawning and handling ctserver. Do not use this alias in your scripts. Its ok to fire its shutdown event to start a safe shutdown.

This will module will probably not work on win32. (windows)


Your session will receive an event 'ct_input' ARG0 will be a parsed version of ARG1. ARG1 is the raw text from the server.

Heres a dump of ARG0, a response from a off_hook event:

                'src' => '3',
                'rly' => 'ctanswer',
                'args' => [
                'dst' => '3',
                'argc' => '1'

This is ARG1 from the above dump.

        rly=ctanswer src=3 dst=3 arg1=OK argc=1

You need to check the first arg of args to see if it is an event like the one listed below.


1, 2, 3, 4, 5, 6, 7, 8, 9, 0, *, #











Connects to the ctserver and port specified in the spawn constructor. You can also pass a hash ref of hostname and port(1-4) to override.


Disconnects from the ctserver.

Note: Disconnecting doesn't stop a currently running record, play, ect.


Takes port off hook, like picking up the phone.


Puts the port on hook, like hanging up the phone.


Blocks until port detects a ring, then returns. The caller ID (if present) will be returned.


Blocks until dial tone detected on port, then returns.

play_tone => $type

Plays a tone. $type can be busy, dialx, dial, or ringback. A warning is produced if you supply an invalid tone.


Stops a playing tone


Stops current playback.

play => $file _or_ play => \@files _or_ play => [ $file1, $file2, $file3 ]

Plays audio files, playing stops immediately if a DTMF key is pressed. Any digits pressed while playing will be added to the digit buffer.

It accepts a space seperated list of files: $kernel->post(ctport => play => "1 2 3");

or an array of files: $kernel->post(ctport => play => ['hello', 'world']);

Filename extensions:

  • The default is .au, can be redefined by posting/calling the default_ext event with the file extension as the first parameter. For example: $kernel->post(ctport => default_ext => '.wav');

  • You can override the default by providing the extension: $kernel->post(ctport => play => "hello.wav");

Searches for file in:

  • The paths defined by set_path event or as an option to the spawn constructor: { path => '/var/audio/files/' }

  • The current directory

  • The "prompts" sub dir (relative to the current directory)

  • full path supplied by caller

  • /var/ctserver/UsMEng

You can play multiple files

$kernel->post(ctport => play => "Hello World"); (assumes you have and files available) (depending on what the default extension is set to)

You can "speak" a limited vocabulary: $kernel->post(ctport => play => "1 2 3");

See the /var/ctserver/UsMEng directory for the list of included files that defines the vocabulary.

record => $file_name => $seconds => $digits

Records $file_name for $seconds seconds or until any of the digits in $digits are pressed. The path of $file_name is considered absolute if there is a leading /, otherwise it is relative to the current directory.


Stops recording on the current port.

sleep => $seconds

Blocks for $seconds, unless a DTMF key is pressed in which case it returns immediately. If $ctport->event() is already defined it returns immediately without sleeping.


Clears the DTMF digit buffer. (It may clear events too!)


Clears the event queue.

collect => $max_digits => $max_seconds

Returns up to $max_digits by waiting up to $max_seconds. Will return as soon as either $max_digits have been collected or $max_seconds have elapsed. On return, the event() method will return undefined.

DTMF digits pressed at any time are collected in the digit buffer. The digit buffer is cleared by the clear method. Thus it is possible for this function to return immediately if there are already $max_digits in the digit buffer.

dial => $number

Dials a DTMF string. Valid characters are 1234567890#*,&

  • , gives a 1 second pause, e.g. $ctport->dial(",,1234) will wait 2 seconds, then dial extension 1234.

  • & generates a hook flash (used for transfers on many PBXs):

    $kernel->post(ctport => dial => '&,1234'); will send a flash, wait one second, then dial 1234.


Blocks, waits for an event to happen. (probably not useful in POE)

send_event => $port => $event

Sends an event or message to another port.

start_timer => $seconds

Starts a timer that will send an event in $seconds seconds.


Stops the current timer.

join => $port1 => $port2

Bridges $port1 and $port2.

bridge => $port

Hardware bridges the connected port to $port.

unbridge => $port

Unbridges the connected port and $port.

join_conference => $port

Joins a port to a conference.

leave_conference => $port

Removes $port from a conference.


Starts ringing the connected port.


Stops the connected port from ringing.


Rings the connected port once.


Turns grunt (non-silence) detection on.


Turns grunt (non-silence) detection on.

default_ext => '.wav'

Changes default extension for playing files.

ignore_dtmf => 1 _or_ 0

Turns on/off the ability for the caller to stop playback with dtmf.

set_script_name => $name

This allows you to set a name on this port. Shown in a port_status event.

send_cid => $number => $name

Sends caller id


Call after teh first ring on trunk port to start listening for caller ID. I'm not sure what JP is, but its not the same as the command below.


Call after teh first ring on trunk port to start listening for caller ID. After the second ring, you should call read_cid to get the caller id if it's available.


Call this after the second ring on a trunk port to receive a caller id event.

port_status => $port

Requests port status on a port, if $port is undef or -2, all ports are polled for status


Tells ctserver to close the current log, and open a new one with the current date


Requests the server version from ctserver


Shutsdown the server and the connection.


The docs are lacking somewhat, so use the source if you get confused.

Automation of the caller_id events into a more simple structure.


Please report any bugs to the author. Patches are welcome.


David Davis, <>

If you use this module, please send comments, complaints or suggetions to the author.



Telephony::CTPort (v0.3 doesn't work with the new ctserver)