1 package FS::part_export::indosoft;
3 use vars qw(@ISA %info $insert_hack);
8 @ISA = qw(FS::part_export);
10 tie my %options, 'Tie::IxHash',
11 'url' => { label => 'Voicebridge API URL' },
12 'account_id' => { label => 'Voicebridge Account ID' },
16 'svc' => 'svc_phone', #svc_bridge? svc_confbridge?
18 'Export conferences to the Indosoft Conference Bridge',
19 'options' => \%options,
21 Export conferences to the Indosoft conference bridge.
22 Net::Indosoft::Voicebridge is required.
28 sub rebless { shift; }
31 my($self, $svc_phone) = (shift, shift);
33 my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
35 my $address = $cust_main->address1;
36 $address .= ' '.$cust_main->address2 if $cust_main->address2;
38 my $phone = $cust_main->daytime || $cust_main->night;
40 my @email = $cust_main->invoicing_list_emailonly;
42 #svc_phone->location_hash stuff? well that was for e911.. this shouldn't
46 my $client_return = eval {
47 indosoft_runcommand( 'addClient',
48 'account_id' => $self->option('account_id'),
50 'client_contact_name' => $cust_main->name, #or just first last?
51 'client_contact_password' => $svc_phone->sip_password, # ?
53 'client_contact_addr' => $address,
54 'client_contact_city' => $cust_main->city,
55 'client_contact_state' => $cust_main->state,
56 'client_contact_country' => $cust_main->country,
57 'client_contact_zip' => $cust_main->zip,
59 'client_contact_phone' => $phone,
60 'client_contact_fax' => $cust_main->fax,
61 'client_contact_email' => $email[0],
66 my $client_id = $client_return->{client_id};
69 my $conf_return = eval {
70 indosoft_runcommand( 'addConference',
71 'client_id' => $client_id,
72 'conference_name' => $cust_main->name,
73 'conference_desc' => $svc_phone->svcnum. ' for '. $cust_main->name,
74 'start_time' => time2str('%Y-%d-$m %T', time), #now, right?? '2010-20-04 16:20:00',
75 #'moderated_flag' => 0,
76 #'entry_ann_flag' => 0
79 #'talk_detect_flag' => 0
80 #'play_user_cnt_flag' => 0
81 #'wait_for_admin' => 0
82 #'stop_on_admin_exit' => 0
84 #'secondary_pin' => 0,
85 #'allow_sub-conf' => 0,
87 #'conference_type' => 'reservation', #'reservationless',
92 my $conference_id = $conf_return->{conference_id};
94 #put conference_id in svc_phone.phonenum (and client_id in... phone_name???)
95 local($insert_hack) = 1;
96 $svc_phone->phonenum($conference_id);
97 $svc_phone->phone_name($client_id);
98 #my $error = $svc_phone->replace;
99 #return $error if $error;
104 sub _export_replace {
105 my( $self, $new, $old ) = (shift, shift, shift);
106 return "can't change phone number as conference_id with indosoft"
107 if $old->phonenum ne $new->phonenum && ! $insert_hack;
114 my( $self, $svc_phone ) = (shift, shift);
117 my $conf_return = eval {
118 indosoft_runcommand( 'deleteConference',
119 'conference_id' => $svc_phone->phonenum,
125 my $client_return = eval {
126 indosoft_runcommand( 'deleteClient',
127 'client_id' => $svc_phone->phone_name,
136 # #these three are optional
137 # # fallback for svc_acct will change and restore password
138 # sub _export_suspend {
139 # my( $self, $svc_phone ) = (shift, shift);
140 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
141 # 'suspend', $svc_phone->username );
142 # ref($err_or_queue) ? '' : $err_or_queue;
145 # sub _export_unsuspend {
146 # my( $self, $svc_phone ) = (shift, shift);
147 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
148 # 'unsuspend', $svc_phone->username );
149 # ref($err_or_queue) ? '' : $err_or_queue;
153 # my($self, $svc_phone, $arrayref) = (shift, shift, shift);
154 # #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_phone->username.
155 # # qq!">!. $svc_phone->username. qq!</A>!;
161 sub indosoft_runcommand {
162 my( $self, $method ) = (shift, shift);
165 $self->option('url'),
172 sub indosoft_command {
173 my( $url, $method, @args ) = @_;
175 eval 'use Net::Indosoft::Voicebridge;';
178 my $vb = new Net::Indosoft::Voicebridge( 'url' => $url );
180 my $return = $vb->$method( @args );
182 die "Indosoft error: ". $return->{'error'} if $return->{'error'};
189 # #a good idea to queue anything that could fail or take any time
190 # sub indosoft_queue {
191 # my( $self, $svcnum, $method ) = (shift, shift, shift);
192 # my $queue = new FS::queue {
193 # 'svcnum' => $svcnum,
194 # 'job' => "FS::part_export::indosoft::indosoft_$method",
196 # $queue->insert( @_ ) or $queue;
199 # sub indosoft_insert { #subroutine, not method
200 # my( $username, $password ) = @_;
201 # #do things with $username and $password
204 # sub indosoft_replace { #subroutine, not method
207 # sub indosoft_delete { #subroutine, not method
208 # my( $username ) = @_;
209 # #do things with $username
212 # sub indosoft_suspend { #subroutine, not method
215 # sub indosoft_unsuspend { #subroutine, not method