Hello Steve,
I did as you said - no luck. here's a snippet from the script that i use and
the code you sent is in there:






class TvrClient

        
        
########## LOKAL        
        private 
        def lokal
                call_log_id = nil
                begin
                        call_log_id = call_log()
                
                        $agi.answer
                
                
                        local_channels = get_locals()
                        dial_params = local_channels.join('&')
                        dial_params << "||m(moh-0900...@moh_id})" if
moh_available?()

                        1.times do
                                r = $agi.exec('DIAL', dial_params)
                                r = $agi.get_variable('DIALSTATUS')
                                $agi.execute('Set(LOC=${CDR(dstchannel)})')
                                retry if r.message.include?('BUSY')
                        end
                        

                ensure
                        call_log(call_log_id) unless call_log_id.nil?
                end
        end
         
        private
        def get_locals
                local_channels = @locals.map { |x| 'SIP/vaso&Zap/' + x.strip
}
                # FIX - 
                raise " settings for telephone_id =
#...@settings_row['telephone_id']}" if local_channels.empty?
                local_channels
        end     


##########


        private
        def moh_available?      
                return false if @settings_row['moh'].strip.empty?
                moh_file = $config[:tvr][:user_sounds_base_folder] + '/' +
@tel_serv_row['tel.account_id'] + '/' + @settings_row['moh'].strip
                File.exists?(moh_file)
        end
        
        private
        def get_moh_file
                moh_file = $config[:tvr][:user_sounds_base_folder] + '/' +
@tel_serv_row['tel.account_id'] + '/' +
File.basename(@settings_row['moh'].strip, '.*')
        end

        private
        def call_log(call_log_id=nil)
                if call_log_id.nil?
                        query = <<-QUERY
                                INSERT INTO call_log SET
                                        starttime = NOW(),
                                        account_id =
#...@tel_serv_row['tel.account_id']},
                                        telephone_id = #...@tel_id},
                                        
                                        service_id =
#...@tel_serv_row['tel.service_id']},
                                        service_name =
'#{$my.quote(@tel_serv_row["ser.name"].to_s)}',
                                        service_type =
'#{$my.quote(@tel_serv_row["ser.type"].to_s)}',
                                        tvr_type =
#...@settings_row['tvr_type']},
                                        
                                        category_id =
#...@tel_serv_row['tel.category_id']},
                                        category_asw =
#...@categories_row['asw']},
                                        category_telekom =
#...@categories_row['telekom']},
                                        
                                        price =
#...@tel_serv_row['tel.price']},
                                        
                                        request =
'#{$my.quote($agi.request.to_s)}',
                                        channel =
'#{$my.quote($agi.channel.to_s)}',
                                        language =
'#{$my.quote($agi.language.to_s)}',
                                        type =
'#{$my.quote($agi.type.to_s)}',
                                        uniqueid =
'#{$my.quote($agi.uniqueid.to_s)}',
                                        callerid =
'#{$my.quote($agi.callerid.to_s)}',
                                        dnid =
'#{$my.quote($agi.dnid.to_s)}',
                                        rdnid =
'#{$my.quote($agi.rdnid.to_s)}',
                                        context =
'#{$my.quote($agi.context.to_s)}',
                                        extension =
'#{$my.quote($agi.extension.to_s)}',
                                        priority =
'#{$my.quote($agi.priority.to_s)}',
                                        enhanced =
'#{$my.quote($agi.enhanced.to_s)}',
                                        accountcode =
'#{$my.quote($agi.accountcode.to_s)}',
                                        callingpres =
'#{$my.quote($agi.callingpres.to_s)}',
                                        callingani2 =
'#{$my.quote($agi.callingani2.to_s)}',
                                        callington =
'#{$my.quote($agi.callington.to_s)}',
                                        callingtns =
'#{$my.quote($agi.callingtns.to_s)}'
                                QUERY
                
                        $my.select_db('tvr2')
                        $my.query(query)
                        raise 'Ne mogu da se upisem u call_log!' if
$my.affected_rows() != 1
                        return $my.insert_id
                else
                        $my.select_db('tvr2')
                        loc = $agi.get_variable('LOC')
                        $my.query("UPDATE call_log SET local = #{loc},
endtime = NOW() WHERE id = #{call_log_id}")
                        raise 'Ne mogu da se ispisem iz call_log-a:
call_log_id = #{call_log_id}' if $my.affected_rows() != 1
                end
                nil
        end


end








Maybe you figure out something.

Zarko








-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Steve Davies
Sent: Monday, July 26, 2010 6:48 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] URgent - capturing 'answered'

On 26 July 2010 17:27, Zarko Zivanovic <[email protected]> wrote:
> I tried this:
>
>
>
> loc = $agi.get_variable('EXTEN')
>
> $my.query("UPDATE call_log SET local = #{loc}, endtime = NOW() WHERE id =
> #{call_log_id}")
>
>
>
> No success. Anybody please help!
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Leif Madsen
> Sent: Monday, July 26, 2010 3:44 PM
> To: [email protected]
> Subject: Re: [asterisk-users] URgent - capturing 'answered'
>
> On 10-07-26 08:10 AM, Zarko Zivanovic wrote:
>> Hello Steve and thanks for your answer,
>> However I tried:
>>
>> $my.query("UPDATE call_log SET local='#{CDR(dstchannel)}', endtime =
NOW()
>> WHERE id = #{call_log_id}")
>>
>> And it does write nothing to the database.
>>
>> I guess there is a error in ruby expression above but I am not sure what
> is
>> wrong - if you have any idea please help.
>
> If that is your literal quote, then I think you need to change the # to a
$
> as
> Asterisk dialplan functions and variables start with ${ vs #{
>
> Unless that is some special indication in SQL that I'm unfamiliar with.
>
> Leif Madsen.


The "#" prefix is probably something to do with the combination of
Ruby, MySQL and AGI - I am not particularly familiar with Ruby.

You do not say at what stage when you call your AGI in the call path,
and at what stage you access the database.

1) Use AGI In order to make the call, and do not exit AGI until after
the call is over:
2) Call AGI after call is over

In case 1) you'll need the following somewhere in your script after
the call is answered or completed.
    $agi.execute('Set(LOC=${CDR(dstchannel)})')
In case 2) just put
    Set(LOC=${CDR(dstchannel)})
in your dialplan before calling the AGI

Then in your script try:
   loc = $agi.get_variable('LOC')

CDR() is a built-in function rather than a variable, hence the need
for the indirection.

I am still guessing a bit here... Good luck.

Cheers,
Steve

-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
               http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5314 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5315 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
               http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to