ASYNC AGI client/Server Framework(ASYNCO)

aioagi的Python项目详细描述


艾奥吉

异步agi客户机/服务器框架。 该项目基于“aiohttp”框架。

主要功能

  • 支持AGI协议的客户端和服务器端。
  • agi服务器有中间件和可插拔路由。

开始

服务器

简单的AGI服务器:

fromaioagiimportrunnerfromaioagi.appimportAGIApplicationfromaioagi.logimportagi_server_loggerfromaioagi.urldispathcerimportAGIViewasyncdefhello(request):message=awaitrequest.agi.stream_file('hello-world')awaitrequest.agi.verbose('Hello handler: {}.'.format(request.rel_url.query))agi_server_logger.debug(message)classHelloView(AGIView):asyncdefsip(self):message=awaitself.request.agi.stream_file('hello-world')awaitself.request.agi.verbose('HelloView handler: {}.'.format(self.request.rel_url.query))agi_server_logger.debug(message)if__name__=='__main__':logging.config.dictConfig(LOGGING)app=AGIApplication()app.router.add_route('SIP','/',hello)runner.run_app(app)

客户

将AGI连接设置为星号:

importasyncioimportlogging.configfromaioagi.logimportagi_client_loggerfromaioagi.clientimportAGIClientSessionfromaioagi.parserimportAGIMessage,AGICodeasyncdeftest_request(loop):headers={'agi_channel':'SIP/100-00000001','agi_language':'ru','agi_uniqueid':'1532375920.8','agi_version':'14.0.1','agi_callerid':'100','agi_calleridname':'test','agi_callingpres':'0','agi_callingani2':'0','agi_callington':'0','agi_callingtns':'0','agi_dnid':'101','agi_rdnis':'unknown','agi_context':'from-internal','agi_extension':'101','agi_priority':'1','agi_enhanced':'0.0','agi_accountcode':'','agi_threadid':'139689736754944',}asyncwithAGIClientSession(headers=headers,loop=loop)assession:asyncwithsession.sip('agi://localhost:8080/hello/?a=test1&b=var1')asresponse:asyncformessageinresponse:client_logger.debug(message)awaitresponse.send(AGIMessage(AGICode.OK,'0',{}))asyncwithsession.sip('agi://localhost:8080/hello-view/?a=test2&b=var2')asresponse:asyncformessageinresponse:client_logger.debug(message)awaitresponse.send(AGIMessage(AGICode.OK,'0',{}))

注意

自动为session.sip('agi://localhost:8080/hello/?a=test1&b=var1')请求设置会话请求头:

agi_type: SIP
agi_network: yes
agi_network_script: hello/
agi_request: agi://localhost:8080/hello/

安装

pip install aioagi

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从浏览器获取URL   JRMP连接建立期间发生java错误   SpringJava。lang.NoClassDefFoundError:org/springframework/beans/factory/BeanNameAware   垃圾收集如何在Java中(有效地)删除最终数组   当您不拥有模型时,java实现MVP?   java Eclipse无法编译粘贴的代码   java一个单元如何测试非确定性加密函数?   java捕获错误消息并显示在控制台(IDE)中   java如何减少完整GC的数量?   java生成axis2 Web服务客户端jar   java列表<List<Integer>>到2D数组的转换(int[]   java安全。getString(mContext.getContentResolver(),“bluetooth_address”)在Android O中返回null   java如何从TCP数据包中获取HTTP正文   base64中带有内联附件的java提取电子邮件正文   java如何使用SQLite在RecyclerView中动态添加按钮