I am writing an IVR and would like to get the keypad number the user dialled and store in in a variable. Does anyone know if asterisk defines such a channel variable? I cannot seem to find in in any variable lists.
I actually not clearly about your question.
As you said : "to get the keypad number the user dialled and store in in a variable"
so it very simple
exten => _X.,1,Noop(User dialed number: ${EXTEN});
So the variable you need is: ${EXTEN}
There are 2 main practice in dooing ivr
exten => s,1,Background(ivr-file-without-extension);play
exten => s,2,WaitExten(); wait for input
exten => 1,1,Noop(1 pressed); do something if 1
exten => 1,2,Set(result=1);for example set variable
Or
exten => s,1,Read(result,ivr-file-without-extension,max_digits);
exten => s,n,Noop(result=${result});
In both variants you can set up ANY variable name, thats why you can't find "magic" variable.
But i highly recommend you first read any single asterisk book for beginners. It is very unlikly you can do working app with your current knowledge(based on question asked).
Related
As i have never done load balancing so i am a bit stuck on this. I would like to know how can i distribute incoming calls from certain number to 2 destination.
So assuming there are 100 calls per hour coming on this extension:
exten => 01234567890,1,Answer
exten => 01234567890,n,Set(oqgroup=BM)
exten => 01234567890,n,Goto(csdigital,csdigital)
How i can distribute these calls on 50/50 basis. So 1st call goes to extension A 2nd call goes to extension B, 3rd goes to A 4th to B etc...
My custom conf where you can see two (example) numbers two which i would like to load balance the incoming calls:
[route]
exten => route,1,Answer
exten => route,n,GotoIf($["${oqgroup}" = "BM"]?bm,1)
exten => bm,1,Dial(SIP/0222333444#outbound,,ro)
exten => bm,1,Dial(SIP/0222333555#outbound,,ro)
You can use function RAND for this.
https://wiki.asterisk.org/wiki/display/AST/Function_RAND
something like this
[route]
exten => route,1,Answer
exten => route,n,Set(my=${RAND(1,2)})
exten => route,n,GotoIf($["${my}" = "1"]?bm,1:bm1,1)
exten => bm,1,Dial(SIP/0222333444#outbound,,ro)
exten => bm1,1,Dial(SIP/0222333555#outbound,,ro)
Please check code, I didn't checked but you should understand logic.
If you don't want to have random(cause some times it might chose randomly to send next call to same extension as before), you can use global variables and create global variable and assign value to it 0. And check before call value of this variable and if it is 0 then route to extension 0222333444 and change value to 1. If global value is 1, then route to other extension and change value to 0 back.
Keep in mind that after asterisk restart global variables are reset to initial value.
I have this drop-down(how_often). If a user select 2 weeks then i want to send an email using delayed jobs like this:
mymailer.delay(:run_at => how_often.from_now).send_email
here I get "2.weeks" in how_often which is a string and the above code doesn't work as we can do as:
mymailer.delay(:run_at => 2.weeks.from_now).send_email
How to convert how_often(string) into reserved words like: 2.weeks, 2.months etc?
you could probably do it with eval:
mymailer.delay(:run_at => eval(how_often).from_now).send_email
I need to generate a random url to my Topic model(for example) as such:
http://localhost:3000/9ARb123
So how can I do this in rails?
Note: the random string must contain digits, small and capital letters.
Something like this perhaps
#config/routes.rb
match "/:random_id" => "topics#show", :constraints => {:random_id => /([a-zA-Z]|\d){3,6}/}
will match a random string of 3-6 random letters/numbers to the show method of your Topics controller. Make sure to declare other resources above this matcher, as something like "http://localhost:3000/pies" will route to Topics#show instead of Pies#index.
To generate a random url for your Topic you can go something like this:
#app/models/topic.rb
before_create :generate_random_id
def generate_random_id
#generates a random hex string of length 6
random_id = SecureRandom.hex(3)
end
Patricks answer should work - but it only covers routing incoming requests.
If you're still using the standard routes (eg topic_path) to create your links, it will still use the normal routes.
If you run rake routes, you should see the name of the route you created with with the random_id. (You may need to name it using :as => 'random_route')
If you call that instead of the standard topic_path you should get the route you are after
Ultimately, I would like to use Inflector.parameterize to create slugs for article heading that have a bunch of unicode chars in them (e.g. "ḤellẒ no" => "hellz-no"). According to http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate it says to put them in the locales/en.yml file.
# Store the transliterations in locales/en.yml
i18n:
transliterate:
rule:
Ḥ: "h"
Ẓ: "z"
I tried that but the following does not work:
"ḤellẒ no".parameterize
# => "ell-no"
However, when I change it in Ruby like the second paragraph suggests, it works.
I18n.backend.store_translations(:en, :i18n => {
:transliterate => {
:rule => {
"Ḥ" => "H",
"Ẓ" => "Z"
}
}
})
"ḤellẒ no".parameterize
# => "hellz-no"
I guess I would like to know why putting the custom transliterations in locales/en.yml doesn't work.
And even if someone give the answer for that, being a Rails noob, I would also like to know where one usually puts code like the second block to manually set the I18n.backend.store_translations?
Ehh, I've got a part of the answer. Unlike what the doc at http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate says, the yml files should still specify the language - i.e. de:
# Store the transliterations in locales/de.yml
de:
i18n:
transliterate:
rule:
ü: "ue"
ö: "oe"
Please still answer the second part of the question, where should code like I18n.backend.store_translations(:en,... live in a Rails 3 app?
[...] where should code like I18n.backend.store_translations(:en,... live in a Rails 3 app?
I know. I might be a little late on this but I would put it into an initializer file: config/initializers/i18n.rb
If I want to mock a class that returns a string that is used to determine whether while loop should continue (imagine read while string != null), how can I set the expectation. I have tried the following:
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20");
provider.Reader.Expect(r => r.ReadLine()).Return(null);
but when it is called twice in the same method, it returns the first string on both occasions, whereas I want it to return the second value (null) if called a second time.
I think you can just stick the repeat on the end of the syntax you're currently using.
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
provider.Reader.Expect(r => r.ReadLine()).Return(null).Repeat.Once();
or
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
provider.Reader.Expect(r => r.ReadLine()).Return(null);
if you have any calls beyond 2nd call that you want to use second expectation.
I'm not familiar with the syntax you're using. I would write this as:
r.ReadLine();
LastCall.Return("1,10,20").Repeat.Once();
r.ReadLine();
LastCall.Return(null).Repeat.Once();
To ensure that you're specifying the number of times that things are to be repeated. (Don't have Visual Studio to hand, syntax may not be exact.)