将 Asterisk 交互程序从命令行 python 脚本迁移到 Web 应用程序
我正在尝试创建一个小型 Web 应用程序来与 Asterisk 电话平台交互。那里有很多类似的东西,但我想要学习制作自己的东西的经验。
这是我现在拥有的:一个简单的 python 脚本,允许某人通过命令行与管理器界面进行交互。该脚本的工作原理基本上是: 1) 连接到 Asterisk 管理器界面。 2) 从 CLI 上的用户获取两个电话号码。 3) 发起两个调用 4) 将发起的呼叫带入公共 Meetme 会议。 5)“while”循环等待用户的输入。只允许使用字符 az。 6) “az”对应于通过使用发起另一个会议而播放或“注入”到会议中的 .WAV 文件 本地扩展。
对我来说,这有点简洁,现在我想从网络应用程序中做同样的事情,但我不知道从哪里开始。我需要使用什么语言?我了解基本的 html 并使用过 javascript。将表单输入变量传递到服务器上的 python 脚本需要什么技术(Web 服务器和星号服务器是同一台机器)?计算机生成图像?使用 PHP 怎么样?我可能需要在某个时候学习这一点...如果我使用 PHP,我仍然可以“调用”python 脚本并向其传递值吗?我希望最终使用 javascript 来允许用户播放与按钮相对应的声音(就像命令行版本中的字符),而无需点击提交,但计划现在就让它工作。我想这个问题也变成了“我应该只学习 PHP 而放弃 python 吗?”我觉得我真的可以通过构建与 Asterisk(也许还有 Freeswitch)交互的基于 Web 的工具来增强我当前的电话技能(并且玩得开心......这个 Asterisk 的东西真是太棒了)。
任何提示或指导将不胜感激。
I am trying to create a small web application to interact with the Asterisk telephony platform. There is a lot of similiar stuff out there but I want the learning experience of making my own.
Here is what I have now: A simple python script that allows someone to interact with the manager interface via the command line. Basically how the script works is:
1) Connects to the Asterisk Manager Interface.
2) Gets two phone numbers from the user on the CLI.
3) Originates the two calls
4) Brings the originated calls into a common meetme conference.
5) A 'while' loop waits for input from the user. Only characters a-z are allowed.
6) "a-z" correspond to .WAV files that are played or "injected" into the conference by the use of originating another
local extension.
To me it is kinda neat and now I want to do the same exact thing from a web app but I don't know where to start. What languages would I need to use? I know basic html and have played with javascript. What techniques would be required to pass form input variables to the python script on the server (web server and asterisk server are the same machine)? CGI? What about using PHP? I will probably need to learn that at somepoint... If I use PHP can I still "call" the python script and pass values to it? I was hoping to use javascript eventually to allow the user to play a sound that corresponds to a button (just like a character in the command line version) without hitting submit but plan on just getting it to work for now. I guess this question is also turning into "Should I just learn PHP and drop the python?" I feel that I could really add to my current telephony skill-set (and have fun... this Asterisk stuff is a blast) by being able to build web based tools that interact with Asterisk (maybe Freeswitch too).
Any hints or guidance would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将您的代码包装在 wsgi 接口中,这是 Web 服务的 Python 标准(类似于 < em>cgi,但用函数代替程序,因此界面更简单,并且可以在Web服务器中预编译)。
WSGI Web 也包含许多 Python Web 应用程序框架的链接,因此请查看它们并选择一个。 Django,Pylons< /a> 或 TurboGears 似乎是更受欢迎的,而 Bottle 非常适合快速组合较小的 Web 应用程序。您最终可能还想看看 Google App Engine,它非常快速地提供了一些受限的 Python 环境托管。
一般来说,Python 拥有出色的 Web 框架,通常比 PHP 更快,并且您可以在网络上和网络外使用相同的技能,而 PHP 在网络之外几乎没有用处。另外,使用 python,您将无法学习将 HTML 与代码混合(如 PHP),如果您要与设计师一起工作,则必须忘记这些内容。
I'd recommend just wrapping the code you have in a wsgi interface, which is python standard for web services (something like cgi but with functions instead of programs, so it has simpler interface and can be precompiled in the web server).
The WSGI web contains links to many python web application frameworks too, so look at them and pick one. Django, Pylons or TurboGears seem to be the more popular ones and Bottle is great for quickly putting together smaller web applications. You might eventually want to also have a look at Google App Engine, which provides somewhat restricted python environment very fast hosting.
Generally python has great web frameworks, is usually faster than PHP and you can use the same skills on and off the web, while PHP is mostly useless outside of web. Also with python, you won't learn to mix HTML with code (as in PHP), which you'd have to unlearn if you ever get to work together with a designer.
如果您愿意,您可以使用 PHP 完成所有操作。但说实话,您已经用 Python 编写了脚本,为什么不直接使用 Python 来处理 Web 内容呢? Django 是最流行的 Web 框架之一。如果您按照教程进行操作,非常容易学习。
对于你想要做的事情来说,Django 可能有点重,但我仍然强烈建议使用它。
在运行 Asterix 的服务器上,使用 mod_wsgi 配置 Apache Web 服务器,以便它可以运行 Python。让您的 Django 包含一个发布到 查看。然后该视图可以执行 Asterix 脚本中的代码。
您将遇到的主要问题是 Web 没有状态。这意味着虽然您可以非常轻松地调用函数,但维护交互式会话可能相当困难。您的
while
循环将很难在 HTTP 会话中维护。您可以使用 commet 之类的东西来维持开放会话,但我没有以前做过这个,我不知道做起来有多容易。我会先尝试一些简单的事情。有一个像这样的Python脚本:
然后在你的django视图中:
这将从源到目标进行调用,然后停止处理。之后您将无法与调用交互(除非您返回一个 ID,这将允许您在 asterix 中进一步操作该调用),但它仍然是一个可靠的起点。
You could do everything from PHP if you wanted to. But honestly, you've written the script in Python already, why not just use Python for the web stuff too? Django is one of the most popular web frameworks around. Very easy to learn if you follow the tutorial.
Django may be a little heavy weight for what you want to do, but I'd still highly recommend using it.
On the server that you have Asterix running on, configure Apache web server with mod_wsgi so that it can run Python. Have your Django contain a form that is posted to a view. That view can then execute code from your Asterix script.
The major problem that you're going to have is that the Web is not stateful. This means that while you can call a function quite easily, maintaining an interactive session can be quite hard. Your
while
loop will be difficult to maintain across a HTTP session. You can use something like commet to maintain an open session, but I've not done this before and I don't know how easy it will be to do.I would try for something simple first. Have a python script such as this:
And then inside your django view:
This will make a call from source to target, and then will stop processing. You won't be able to interact with the call after that (unless you return an ID which will allow you to manipulate that call further within asterix), but it will still be a solid place to start.