Skip to Content
《Asterisk:权威指南》第 5 版
book

《Asterisk:权威指南》第 5 版

by Jim Van Meggelen, Russell Bryant, Leif Madsen
May 2025
Intermediate to advanced
414 pages
5h 2m
Chinese
O'Reilly Media, Inc.
Content preview from 《Asterisk:权威指南》第 5 版

第 18 章 Asterisk 网关界面

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

咖啡因。毒品的入口

埃迪-维德

Asterisk 拨号规划已发展成为一个简单而强大的呼叫处理编程接口。然而,许多人,尤其是有编程背景的人,更喜欢用传统编程语言实现呼叫处理。Asterisk 网关接口(AGI)允许使用您选择的编程语言开发第一方呼叫控制功能。

快速入门

本节提供了一个使用 AGI 的快速示例 。

首先,让我们创建要运行的脚本。AGI 脚本通常放在/var/lib/asterisk/agi-bin 中

$ cd /var/lib/asterisk/agi-bin

$ vim hello-world.sh

#!/bin/bash

# Consume all variables sent by Asterisk
while read VAR && [ -n ${VAR} ] ; do : ; done

# Answer the call.
echo "ANSWER"
read RESPONSE

# Say the letters of "Hello World"
echo 'SAY ALPHA "Hello World" ""'
read RESPONSE

exit 0

$ chown asterisk:asterisk hello-world.sh

$ chmod 700 hello-world.sh

现在,在[sets] 上下文中将以下一行添加到/etc/asterisk/extensions.conf 中:

exten => 237,1,AGI(hello-world.sh)

保存并重新加载拨号计划,当你呼叫分机 237 时,你应该能听到 Allison 说出 "Hello World"。

AGI 变体

AGI 有几种变体,主要区别在于与Asterisk 通信的方法不同。最好能了解所有选项,以便根据应用程序的需要做出最佳选择。

基于流程的 AGI

基于进程的 AGI 是 AGI 的最简单变体。本章开头的快速启动示例就是一个基于进程的 AGI 脚本示例。该脚本使用 AGI()应用程序来调用脚本。要运行的应用程序被指定为AGI() 的第一个参数。除非指定了完整路径,否则该应用程序应位于/var/lib/asterisk/agi-bin目录中。 要传递给 AGI 应用程序的参数可作为AGI()应用程序的附加参数在Asteriskdialplan 中指定。语法如下

AGI(command[,arg1[,arg2[,...]]])
提示

确保您的应用程序设置了适当的权限,以便 Asterisk 进程用户拥有执行权限。否则,AGI() 将失败。

Asterisk 执行 AGI 应用程序后,Asterisk 与应用程序之间的通信将通过stdinstdout 进行。AGI 通信概述 "将介绍有关该通信的更多详情有关从拨号计划调用AGI() 的更多详情,请查阅Asterisk 内置的文档:

*CLI> core show application AGI
基于流程的 AGI 的优点

这是最简单的 AGI 实现形式。

基于流程的 AGI 的缺点

就资源消耗而言,这是效率最低的 AGI 形式。负载较高的系统应考虑"FastAGI-AGI over TCP"中讨论的FastAGI

EAGI

EAGI(增强型 AGI )是AGI() 的一个小变种。它在Asterisk 拨号计划中的调用方式与EAGI() 相同。不同之处在于,除了stdinstdout ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho

Publisher Resources

ISBN: 9798341659568