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,
22 Export conferences to the Indosoft conference bridge.
23 Net::Indosoft::Voicebridge is required.
29 sub rebless { shift; }
32 my($self, $svc_phone) = (shift, shift);
34 my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
36 my $address = $cust_main->address1;
37 $address .= ' '.$cust_main->address2 if $cust_main->address2;
39 my $phone = $cust_main->daytime || $cust_main->night;
41 my @email = $cust_main->invoicing_list_emailonly;
43 #svc_phone->location_hash stuff? well that was for e911.. this shouldn't
47 my $client_return = eval {
48 indosoft_runcommand( 'addClient',
49 'account_id' => $self->option('account_id'),
51 'client_contact_name' => $cust_main->name, #or just first last?
52 'client_contact_password' => $svc_phone->sip_password, # ?
54 'client_contact_addr' => $address,
55 'client_contact_city' => $cust_main->city,
56 'client_contact_state' => $cust_main->state,
57 'client_contact_country' => $cust_main->country,
58 'client_contact_zip' => $cust_main->zip,
60 'client_contact_phone' => $phone,
61 'client_contact_fax' => $cust_main->fax,
62 'client_contact_email' => $email[0],
67 my $client_id = $client_return->{client_id};
70 my $conf_return = eval {
71 indosoft_runcommand( 'addConference',
72 'client_id' => $client_id,
73 'conference_name' => $cust_main->name,
74 'conference_desc' => $svc_phone->svcnum. ' for '. $cust_main->name,
75 'start_time' => time2str('%Y-%d-$m %T', time), #now, right?? '2010-20-04 16:20:00',
76 #'moderated_flag' => 0,
77 #'entry_ann_flag' => 0
80 #'talk_detect_flag' => 0
81 #'play_user_cnt_flag' => 0
82 #'wait_for_admin' => 0
83 #'stop_on_admin_exit' => 0
85 #'secondary_pin' => 0,
86 #'allow_sub-conf' => 0,
88 #'conference_type' => 'reservation', #'reservationless',
93 my $conference_id = $conf_return->{conference_id};
95 #put conference_id in svc_phone.phonenum (and client_id in... phone_name???)
96 local($insert_hack) = 1;
97 $svc_phone->phonenum($conference_id);
98 $svc_phone->phone_name($client_id);
99 #my $error = $svc_phone->replace;
100 #return $error if $error;
105 sub _export_replace {
106 my( $self, $new, $old ) = (shift, shift, shift);
107 return "can't change phone number as conference_id with indosoft"
108 if $old->phonenum ne $new->phonenum && ! $insert_hack;
115 my( $self, $svc_phone ) = (shift, shift);
118 my $conf_return = eval {
119 indosoft_runcommand( 'deleteConference',
120 'conference_id' => $svc_phone->phonenum,
126 my $client_return = eval {
127 indosoft_runcommand( 'deleteClient',
128 'client_id' => $svc_phone->phone_name,
137 # #these three are optional
138 # # fallback for svc_acct will change and restore password
139 # sub _export_suspend {
140 # my( $self, $svc_phone ) = (shift, shift);
141 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
142 # 'suspend', $svc_phone->username );
143 # ref($err_or_queue) ? '' : $err_or_queue;
146 # sub _export_unsuspend {
147 # my( $self, $svc_phone ) = (shift, shift);
148 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
149 # 'unsuspend', $svc_phone->username );
150 # ref($err_or_queue) ? '' : $err_or_queue;
154 # my($self, $svc_phone, $arrayref) = (shift, shift, shift);
155 # #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_phone->username.
156 # # qq!">!. $svc_phone->username. qq!</A>!;
162 sub indosoft_runcommand {
163 my( $self, $method ) = (shift, shift);
166 $self->option('url'),
173 sub indosoft_command {
174 my( $url, $method, @args ) = @_;
176 eval 'use Net::Indosoft::Voicebridge;';
179 my $vb = new Net::Indosoft::Voicebridge( 'url' => $url );
181 my $return = $vb->$method( @args );
183 die "Indosoft error: ". $return->{'error'} if $return->{'error'};
190 # #a good idea to queue anything that could fail or take any time
191 # sub indosoft_queue {
192 # my( $self, $svcnum, $method ) = (shift, shift, shift);
193 # my $queue = new FS::queue {
194 # 'svcnum' => $svcnum,
195 # 'job' => "FS::part_export::indosoft::indosoft_$method",
197 # $queue->insert( @_ ) or $queue;
200 # sub indosoft_insert { #subroutine, not method
201 # my( $username, $password ) = @_;
202 # #do things with $username and $password
205 # sub indosoft_replace { #subroutine, not method
208 # sub indosoft_delete { #subroutine, not method
209 # my( $username ) = @_;
210 # #do things with $username
213 # sub indosoft_suspend { #subroutine, not method
216 # sub indosoft_unsuspend { #subroutine, not method