Skip to content

Instantly share code, notes, and snippets.

View andrius's full-sized avatar

Andrius Kairiukstis andrius

View GitHub Profile
@andrius
andrius / VoIP-questionnaire.rb
Last active December 12, 2015 12:39
Questionnaire application, includes database and Asterisk AGI (from line 100). For new caller, app request to enter an PIN code to authenticate. App monitors how many times caller was returned to the system and how many attempts did to answer question.
#!/bin/env ruby
# This application was made and tested in production with Ruby 1.8x
require 'rubygems'
require 'mysql'
require 'active_record'
require 'AGIServer'
require 'AGIMenu'
require 'AGISelection'
@andrius
andrius / gist:4984463
Created February 19, 2013 09:45
Old AGI sample of manipulaiton with dynamic agents for asterisk 1.2 and 1.4
#!/usr/bin/ruby
require 'rubygems'
require 'rastman'
require 'AGIServer'
require 'AGISelection'
require 'AGIMenu'
AMI = Rastman::Manager.new(@@config[:manager][:user],
@@config[:manager][:secret],
@andrius
andrius / business-times.rb
Created February 22, 2013 22:34
Business time management for Ruby application Say, application need to manage time flexible, what do you think about this implementation?
# Migration
create_table :business_time_members do |t|
t.string :name, :limit => 100
t.integer :business_time_id
t.time :time_from, :default => '2000-01-01 00:00:00'
t.time :time_to, :default => '2000-01-01 23:59:59'
t.integer :weekday # 0 - sunday, 1 - monday, 2 -tuesday, ...
t.integer :day_of_month # 1-31
t.integer :month # 1-12
@andrius
andrius / ruby-agi-daemon.rb
Created February 25, 2013 10:02
How to daemonise Ruby AGI app.
#!/usr/bin/env ruby
# NOTE - Following code was tested with AsteriskRuby gem and Adhearsion v. 1.2.3
require 'rubygems'
require 'pp'
require 'monitor'
require 'timeout'
require 'time'
require 'AGIServer'
#!/usr/bin/env ruby
require 'monitor'
require 'pp'
require 'timeout'
require 'time'
require 'pp'
require 'rubygems'
require 'AGIServer'
desc "Loads initial data (use once after migration)"
task "db:initialize" do
require './lib/initialize'
require 'fileutils'
# Print out DB log
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.level = Logger::DEBUG
YAML::load_file("#{APP_ROOT}/config/pbxes.yml").each_pair do |name,params|
@andrius
andrius / download-and-install.sh
Created March 14, 2013 23:16
Script to download and install Asterisk PBX, Ruby and Adhearsion AGI on debian-based system
#!/bin/bash
# function to generate random password, on input requires an argument - lenght of password
genpasswd() {
local l=$1
[ "$l" == "" ] && l=20
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
# MySQL default root password
@andrius
andrius / campaign-next-number.rb
Created April 16, 2013 20:55
Any way to optimize? To ensure that its working on MySQL, SQLITE, Postgre SQL?
# Find next number to send call
def next_number
# first parse CDRs
Cdr.parse
# find number
sql_request = %{campaign_id = ? and
call_state = ? and
number_of_retries < ? and
(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(updated_at)) <= ?
@andrius
andrius / tts.sh
Last active June 8, 2022 17:27
Quick and dirty IVR sounds for your Asterisk PBX
#!/bin/bash
#title : tts.sh
#description : This script will convert text to speech using Google translate API
# and then to Asterisk formats (wav, sln, gsm)
#
#author : Andrius Kairiukstis <[email protected]>
#date : 26 July 2013
#version : 0.1
#usage : bash tts.sh FILENAME VOICE PHRASE
@andrius
andrius / ahn
Created August 20, 2013 20:34 — forked from ik5/ahn
#!/bin/sh
### BEGIN INIT INFO
# Provides: ahn
# Required-Start: ahn daemon
# Required-Stop: ahn daemon
# chkconfig: 2345 91 60
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Adhearsion daemon