FreeSWITCH dynamic IVR entry/bridge - php

Not sure what's the best approach to do this and not even sure if it's doable. I have PHP and MySQL, FreeSWITCH, FreeSWITCH PHP ESL setup on my server and a SIP phone number binded to the gateway. In the database I have a table storing pairs of phone numbers that I want to bridge calls between. A short version of the table looks like below:
+-----+--------------+--------------+
| | Callee_1 | Callee_2 |
+-----+--------------+--------------+
| 1 | 1112223333 | 2223334444 |
| 2 | 6667778888 | 7778889999 |
| 3 | 1123581321 | 3455891442 |
+-----+--------------+--------------+
What I've been trying to achieve is to build a automated call center with FreeSWITCH in a way that I can make an automated call to Callee_1 in the table and play an IVR once Callee_1 picks up. If Callee_1 presses 1 I will bridge the the call to Callee_2 so they can speak on the phone.
I was thinking about to setup a CronJob that fetches new rows from the table periodically then loop through them and use PHP ESL to originate calls to Callee_1. Something like
$sock->api("originate sofia/gateway/myProvider/$Callee_1 &ivr(my_ivr)");
my_ivr:
<menu name="my_ivr"
greet-long="say:Thank you for filling out the form."
greet-short="say:Thank you.
......
digit-len="4">
<entry action="menu-exec-app" digit="1" param="bridge sofia/gateway/myProvider/Callee_2/>
</menu>
Everything seems fine up till now yet I ran into the problem of how to pass the corresponding Callee_2's phone number to the IVR entry dynamically. Should I rewrite the ivr xml and do a reload for every pair? I tried configuring the mod_xml_curl yet no luck. The fs_cli generates "405 not allowed" error every time I try to reload IVR. I also checked out the HTTAPI seems it doesn't fit my need here as it requires using session.
Any insight is appreciated. Thanks!

I'm the OP and now answering my own question. It turned out that I was over complicating the whole thing and FreeSWITCH is extremely intuitive to use. Simply setting a channel variable
originate {callee_2=2223334444}sofia/gateway/myProvider/1112223333 &ivr(my_ivr)
and accessing the channel variable in the ivr xml
<menu name="my_ivr"
greet-long="say:Thank you for filling out the form."
greet-short="say:Thank you.
......
digit-len="4">
<entry action="menu-exec-app" digit="1" param="bridge sofia/gateway/myProvider/${callee_2}/>
</menu>
will do the trick. Hopefully it helps.

in menu-exec-app, you can execute a Lua or some other script which looks up the destination in the database.

Related

How to store different type of data depending on selected option

I'm currently creating a contest system in PHP. For the database, I use MySQL.
When a users wants to make an submission, he can chose between 2 types of entry:
Link to a program
The program itself.
On my website, users can also create programs using a full coding environment I provide on the site. These programs then get stored to my database in the table scripts, which has the colums
user (representing the user ID)
script_id (representing the script ID)
name (representing the name of the program)
script (LongText representing the code of the program itself)
Now, if a user was up to make an submission, he can decide whether his submissionshould be a link to a program or a program he previously created on my website.
If he goes for the full program, he'll have to select one from a dropdown.
My question is all about the server side.
When the user than clicks "Submit", a JSON formatted string containing the type of the submission (0 or 1) and the payload (a long string containing either the link or the script_id).
Now on the server side, I got these information and I want to store the user's submission.
Now here's the actual question:
How can I store this information so that I can easily access the submission's type and its value (either a link or a full source code)?
I do not want to save the whole sourcecode of the script once again, because the user already did that, it's stored in the table scripts.
I thought about something like:
*---------------------------------*
| submission_type | value |
*---------------------------------*
| 0 | google.com |
*---------------------------------*
| 0 | stackoverf |
*---------------------------------*
| 1 | 3 |
*---------------------------------*
| 1 | 10 |
*---------------------------------*
But that would be kind of messed up, because I do not want to have either a string or an int in the value column.
What do you think is the best way to store this data of unknown type?
In the db you only need a table scripts and a table submission.
In the PHP page when user select "Link to a program" you call the add submission function with: USER_ID, SCRIPT_ID
But if user select "The program itself" first you call a function to create the script using the LongText representing the code of the program itself. After that you now have a script_id so call the submission function as above.

Use mysql to create a modified string searching for words within that string contained in a table

I hope I can explain well enough what I am looking for. I tried doing some searches on here, but wasn't finding what I want. I want to do this with strictly mysql if I can with no PHP involved.
So I have a table with terms in it with URL links for each term, we'll call that terms. I have another table with short paragraphs of text we'll call paragraphs. What I want to do is select a paragraph from the table and search it for any of the words contained in the terms table. If the term is in the text, I want to replace it with a concatenated html anchor tag using data from the terms table. I then want the paragraph returned as a formatted string with the anchor tags in place. This way if I add or remove terms to or from the table, I always get a paragraph formatted with the most up to date terms.
Let me know if this is too confusing and I'll see if I can explain it better. Also, if I missed something in my searching that is already posted for this, feel free to guide me in that direction.
Thanks in advance for any help.
-------------------------------------------------
Edit: Here is an example.
-------------------------------------------------
`terms` table
-------------------------------------------------
ID | term | URL
---|----------|----------------------------------
1 | printer | http://t-shooting.link/printers
2 | scanner | http://t-shooting.link/scanners
3 | copier | http://t-shooting.link/copier
-------------------------------------------------
`problems` table
ID | problem
---|---------------------------------------------
1 | the two printers (side by side) need cleaning as the
| copies from them come out with streaks.
2 | My computer won't recognize scanner when I try to use
| it. I was able to use the copier to scan for now, but
| it would be nice to use the scanner that I have in my
| room.
So if I select ID 2 from the problems table I need it to search for any words contained in the terms table and replace them with a mysql "CONCAT('', terms.term, '')" or however I decide to format that. This would make the paragraph look like this:
My computer won't recognize scanner when I try to use it. I was able to use the copier to scan for now, but it would be nice to use the scanner that I have in my room.
The more I do on the mysql side, the less overhead I have on the PHP side. I know ways to do this in PHP, I am just wondering if there is a way to do it in mysql.
Does that help a bit?

Making a database scalable

I've been developing a website for some time now and so far everything is fast and good, though that is with one active user. I don't know how many people will use my website in the first, week, month or year.
I've been looking into what scaling means and how to achieve it and caching seems to be a big part of it. So I started searching for ways to cache my content. Currently I've just developed the website in XAMPP. I'm using MySQL for the database and simple PHP with MySQLi to edit the data. I also do some simply logging with the built-in System Messages app in OS X Mountain Lion. So I'm thinking about using Memcache for the caching.
Is this a good approach?
How can I test it to really see the difference?
How do I know that it will work great even with many more users?
Are there any good benchmarking apps out there?
There are many ways to make sure that a database scales well, but I think the most important part is that you define proper indexes for your tables. At least the fields that are foreign keys should have an index defined.
For example, if you have a large forum, you might have a table of topics that looks like this:
topic_id | name
---------+--------------------------------
1 | "My first topic!"
2 | "Important topic"
3 | "I really like to make topics!"
... | ...
7234723 | "We have a lot of topics!"
And then another table with the actual posts in the topics:
post_id | user | topic_id
---------+------------+---------
1 | "Spammer" | 1
2 | "Erfa" | 2
3 | "Erfa" | 1
4 | "Spammer" | 1
... | ... | ...
87342352 | "Erfa" | 457454
When you load a topic in your application, you want to load all posts that match the topic id. In this case, you cannot afford to look through all database rows, because there are simply too many! Fortunately, you do not have to do much to make sure this is done, you just have to create an index for the field topic_id and you are done.
This is a very basic thing to do to make your database scale well, but since it is so important, I really thought someone should mention it!
Get and Use jMeter.
with jMeter you can test how quick responses are coming back and how pages are loading in addition to confirming that there aren't any errors currently going on. This way you can simulate a ton of load; while seeing actual performance updates when making an adjustment such as using memcache.

Yii - creating a link from data stored in a table

Ive been trying to think of / find a solution to an issue i have. Im creating a menu system for my Yii app but I need to store part of the items need for creating the URL in a table.
I have a table called system_menu_item:
---------------------------------------------------------------------|
item_id | dis_text | action | variables |
---------------------------------------------------------------------|
1 | edit article | document/view | array('id'=>$model->arl_id) |
What i was hoping for was:
$model = SystemMenuItem::model()->findByPk('1');
$url = yii::app()->createUrl($model->action, $model->variables);
This doesn't work.. I tried different ways of doing it all not working. Any ideas?
Thanks
I'm going to guess the issue is that $model->variables evaluates to a string with the value array('id'=>$mode->arl_id).
An ugly (and dangerous!) hack would be to read this in using eval()
A better way would be to probably figure out a different way to store your parameters, and read them into an array after performing your DB query.

How to access a website's url programmatically from within the page

For work, I am working on a site that has a feature that lets users make custom instances of the site depending on who they want to show it to. So if they want to show their potential employer a little bit about themselves, they can send them a custom url, that has a uid on the end of it that tells the database what to show and what not to when the site is loaded up.
Now, I need to be able to take the value that is on the end of the url, this unique uid that corresponds with their preferences in the db, accessable on run time. Meaning that when someone types in this custom url, I need to be able to show the name of the person whose portfolio is being viewed BEFORE password authentication takes place...
If I could get the URL, I suppose I could parse through it to find the necessary UID...but how do I get the url? Maybe I am just missing something here, but if anyone has any thoughts or ideas, it would be appreciated!! Thanks
Sorry, to further clarify, I am using PHP to handle calls to the database...
Did you know dynamic web site technologies do just that?
There are lots of them and it is fairly easy to get the parameters from the URL.
Examples :
PHP:
http://www.example.com/show.php?uid=123
$_GET['uid'];
JSP:
http://www.example.com/show.jsp?uid=123
request.getParameter("uid");
There are so many of them it's pointless to enumerate them here
If you are using a server-side language, you can get any part of the url easily, for example, in php, it can be gotten through $_GET array and other arrays. If you want it with javascript, you can do like:
JS Example:
var url_array = document.location.href.split('/');
echo url_array[0]; // part one
echo url_array[1]; // part two
echo url_array[2]; // part three
You can even get the host part with:
alert(document.location.host);
PHP Example:
www.mysite.com?id=100
echo $_GET['id'];
This would depend on what language you are using, but typically that uid at the end of the URL would be passed as a request parameter, like this:
www.mysite.com/info?uid=dkafdojoapjdopakd
You would then access it in your code using the request parameters. So, in PHP, it would be:
$uid = $_GET['uid'];
// get the appropriate data for this uid, write out the page contents, etc.
First store each user's preferences as a piece of css within html style tags
+-----------+---------------+
| UID | style |
+-----------+---------------+
| 0z65dbr | <style>h1{ |
| | font-family: |
| | arial, |
| | sans-serif |
| | }</style> |
+-----------+---------------+
Then setting the get variable 'uid' in the url eg. www.example.com/page?uid=0z65dbr you can extract the value form the uid variable in php with $_GET['uid'] and pass this value to your sql query:
$sql = "SELECT style FROM styles WHERE UID = '".mysql_real_escape_string($_GET['uid'])."'";
Then in the put the result of executing the query into the head section of the html.

Categories