http://www.mundoopensource.com.br/en_page_xmpp_asterisk_pratical_example/

www.mundoopensource.com.br/xmpp-asterisk-integration-practical-example-part-2/

In past few years integrate XMPP and Asterisk is one of my principal goals. The development of an realtime communication tool with open source software necessarily needs this two technologies and make it happens is one of my intents.

Nine years ago, since I started to work with Asterisk and Openfire I’m studying a way to do it and when I discovered that Asterisk 11 had improved xmpp support, I noticed that it was the time to make this real.

Using AGIs scripts in python, I started the development of a “tool” that allows users to run commands through their xmpp account in their preferred xmpp client (Pidgin, for example). The current version of my software permits:

Send SIP messages to an extension
    Send text messages (SMS)
    Enable/disable DND for extension
    Enable/disable divert for extension
    Queue logon/logoff
    Show extension informations
    Show queue informations
    Send XMPP message to all extensions logged in a queue
    Show SIP and IAX peers informations
    And other resources under development

For it works you’ll need to create a column in your SIP table to store the extension’s JID. I created a column named JID in my sippeers table.

Now I’ll show you a practical example of this integration.

What do you need?

You’ll need this following items:

A running Asterisk 11 (at least) with res_xmpp support configured.
    A running XMPP server (Openfire 3.9.3 is a good one)
    A JID account for your Asterisk (to use in res_xmpp)

And now ?

First you need to make Asterisk works with your XMPP server. Edit /etc/asterisk/xmpp.conf and create a sessions for you server. Example:

[asterisk]
type=client
serverhost=yourjabberdomain
username=asterisk@yourjabberdomain
secret=password
priority=1
usetls=yes
port=5222
usesasl=yes
status=available
statusmessage="Asterisk Server"
endtodialplan=yes
context=from_xmpp
keepalive=yes

After, edit /etc/asterisk/extensions.conf and create  from_xmpp context with the following content:

[from_xmpp]

exten => s,1,NoOp(XMPP Message)
same => n,NoOp(To: ${MESSAGE(to)})
same => n,NoOp(From: ${MESSAGE(from)})
same => n,NoOp(Message: ${MESSAGE(body)})

same => n,NoOp(Sending SIP message)

; AGI that process message and get the following variables
; ${XMPP_MSG} - message text
; ${XMPP_SIPDEST} - to extension
; ${XMPP_SIPORIG}  - from extension
same => n,agi(process_xmpp_msg.agi)

; Set ${XMPPRESOURCE} = session name in xmpp.conf file (can be a global variable)
same => n,Set(XMPPRESOURCE=asterisk)

same => n,Set(MESSAGE(body)=${XMPP_MSG})
same => n,MessageSend(sip:${XMPP_SIPDEST},sip:${XMPP_SIPORIG})
same => n,JabberSend(${XMPPRESOURCE},${MESSAGE(from):5},"Message sent. Status:${MESSAGE_SEND_STATUS}). )

How to use it?

To  “communicate” with your Asterisk server just send messages to Asterisk JID configured in your xmpp.conf file (in this example, asterisk@yourjabberdomain). The message will be received in xmpp context (from_xmpp context) and stored in  ${MESSAGE} variable. The NoOP commands in the example context are used just to show you  how Asterisk processes the message.

UPDATE: some readers ask me to send my process_xmpp_msg.agi. You can get it here. It was adapted from my original script, so I hope it is working.

XMPP and Asterisk integration的更多相关文章

  1. Xmpp integration with Asterisk

    http://gnu-linux.org/xmpp-integration-with-asterisk.html Xmpp stands for eXtensible Messaging and Pr ...

  2. Github上的原文XMPP环境搭建步骤,英语能力差不多的可以看看

    Getting started using XMPPFramework on iOS Here is a post on StackOverflow describing how to install ...

  3. xmpp muc 群聊协议 4

    7. Occupant Use Cases The main actor in a multi-user chat environment is the occupant, who can be sa ...

  4. [转] Spring Integration 系统集成

    [From] http://blog.csdn.net/w_x_z_/article/details/53316618 pring Ingegration 提供了基于Spring的EIP(Enterp ...

  5. 转 asterisk app命令中文翻译

    常规指令 Authenticate:鉴别用户 VMAuthenticate:根据“voicemail.conf”鉴别用户 Curl:接受外接URLs的修复.支持POSTing DUNDiLookup: ...

  6. xmpp之配置Xcode(1)

    介绍 ios上的XMPPFramework你能够在Xcode/iPhoneXMPP 目录找到,它只是实现了XMPP的一小部分功能. 下面主要介绍在开发XMPPFramework ios应用之前的配置工 ...

  7. 在 Laravel 中使用图片处理库 Integration/Image

    系统需求 PHP >= 5.3 Fileinfo Extension GD Library (>=2.0) … or … Imagick PHP extension (>=6.5.7 ...

  8. 技术笔记:XMPP之openfire+spark+smack

    在即时通信这个领域目前只找到一个XMPP协议,在其协议基础上还是有许多成熟的产品,而且是开源的.所以还是想在这个领域多多了解一下. XMPP协议:具体的概念我就不写了,毕竟这东西网上到处是.简单的说就 ...

  9. 按照Enterprise Integration Pattern搭建服务系统

    在前一篇文章中,我们已经对Enterprise Integration Pattern中所包含的各个组成进行了简单地介绍.限于篇幅(20页Word以内),我并没有深入地讨论各个组成.但是如果要真正地按 ...

随机推荐

  1. Twisted介绍

    Twisted诞生于2000年初,作者为Glyph,目的是为了开发网络游戏. Twisted的历史 Glyph开始采用Java多线程,来开发Twisted Reality,结果多线程使得开发变得复杂, ...

  2. GCDTimer

    #import <Foundation/Foundation.h> @interface JKTimerManager : NSObject + (instancetype)sharedT ...

  3. Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies

    Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction pol ...

  4. POJ 1014 Dividing 多重背包

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63980   Accepted: 16591 Descri ...

  5. winform程序开机自动启动代码

    几天前头儿要我实现程序能开机自动启动,搞好了,整理起来写下来. private void checkBox1_CheckedChanged(object sender, EventArgs e) { ...

  6. JavaScript学习总结【8】、面向对象编程

    1.什么是面向对象编程 要理解面向对象,得先搞清楚什么是对象,首先需要明确一点这里所说的对象,不是生活中的搞男女朋友对象,面向对象就是面向着对象,换在代码中,就是一段代码相中了另一段代码,自此夜以继日 ...

  7. 学渣也要搞 laravel(1)—— 安装篇

    看到laravel(我叫它:拉瓦)那么热门,我也决定学上一学. Laravel 5.2 在 5.1 基础上继续改进和优化,添加了许多新的功能特性:多认证驱动支持.隐式模型绑定.简化Eloquent 全 ...

  8. cx_Oracle使用方法一

    cx_Oracle使用方法 正确安装好cx_oracle之后,要使用它来连接到oracle数据库进行操作,具体应该分3步走: 第一步:导入cx_Oracle ,建立连接 >>> im ...

  9. 基于python做的抓图程序1.0.00版本

    #coding=gbkimport urllibimport urllib2import reimport osimport time# import readline def getHtml(url ...

  10. 《C和指针》章节后编程练习解答参考——6.6

    <C和指针>——6.6 题目: 在指定的下限.上限之间使用数组方法查找质数,并将质数提取出来. 要求: 略 解答代码: #include <stdio.h> #define U ...