forked from englercj/node-esl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## Chatty | ||
|
||
Chatty is a simple application to test FreeSWITCH SMS and ESL capabilities. It presents | ||
a real-time webchat with a cell phone via text messages. | ||
|
||
![Can't Talk][1] | ||
|
||
### Installation | ||
|
||
simply run npm install from within the `examples/chatty` directory | ||
|
||
```shell | ||
cd examples/chatty | ||
npm install | ||
``` | ||
|
||
Make sure you make the action in your chatplan include `application="fire"` or the events | ||
will not fire over ESL. | ||
|
||
Here is an example `conf/chatplan/default.xml` | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<include> | ||
<context name="default"> | ||
|
||
<extension name="demo"> | ||
<condition field="to" expression="^(.*)$"> | ||
<action application="fire" data=""/> | ||
</condition> | ||
</extension> | ||
|
||
</context> | ||
</include> | ||
``` | ||
|
||
### Usage | ||
|
||
To start the server, run the executable: | ||
|
||
```shell | ||
cd examples/chatty | ||
./bin/chatty | ||
``` | ||
|
||
Then navigate your browser to `http://server:8181`. If you have you config.json configured | ||
properly then you should be able to send and receive SMS messages from the web interface. | ||
|
||
|
||
[1]: http://www.stuffistumbledupon.com/wp-content/uploads/2012/04/Rabbit-Meme-Playing-PS3-Videogames-cant-talk-now-boss-fight-lol-lulz-funny-joke-pictures-animals.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
var Chatty = require('../lib/chatty').Chatty, | ||
config = require('../config.json'); | ||
|
||
var app = new Chatty(config.server); | ||
|
||
app.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"fsw": { | ||
"host": "127.0.0.1", | ||
"port": 8021, | ||
"password": "ClueCon" | ||
}, | ||
"server": { | ||
"host": "0.0.0.0", | ||
"port": 8181, | ||
"provider": "sms-proxy.yourprovider.com", | ||
"from": "from_number@from_host", | ||
"profile": "external" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
var http = require('http'), | ||
express = require('express'), | ||
sio = require('socket.io'), | ||
esl = require('modesl'); | ||
|
||
var Chatty = exports.Chatty = function(opts) { | ||
opts = opts || {}; | ||
|
||
this.port = opts.port || 8181; | ||
this.host = opts.host || '0.0.0.0'; | ||
this.provider = opts.provider || 'sms-proxy-01.bandwidthclec.com'; | ||
this.from = opts.from || '19515529832@199.44.241.115'; | ||
this.profile = opts.profile || 'external'; | ||
|
||
this.app = express(); | ||
|
||
this.config = require('../config.json'); | ||
|
||
this.clients = {}; | ||
|
||
this.lastSeq = 0; | ||
}; | ||
|
||
Chatty.prototype._configure = function() { | ||
var self = this; | ||
|
||
self.app.use(express.static('public')); | ||
|
||
self.io.set('log level', 1); | ||
}; | ||
|
||
Chatty.prototype._init = function() { | ||
var self = this; | ||
|
||
//self.app.get('/', function(req, res) { | ||
//res.render('index.html'); | ||
//}); | ||
|
||
self.io.on('connection', function(socket) { | ||
socket.on('setup', function(num, fn) { | ||
if(num.length === 10) num = '1' + num.toString(); | ||
|
||
self.clients[num.toString()] = socket; | ||
socket.set('number', num.toString(), function() { | ||
fn(); | ||
}); | ||
}); | ||
|
||
socket.on('sendmsg', function(msg, fn) { | ||
socket.get('number', function(err, num) { | ||
self.fsw.message(num + '@' + self.provider, self.from, self.profile, msg, function(evt) { | ||
fn(evt.serialize('json')); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
Chatty.prototype.start = function() { | ||
var self = this; | ||
|
||
self.server = self.app.listen(self.port, self.host); | ||
self.io = sio.listen(self.server); | ||
|
||
//connect to freeswitch | ||
self.fsw = new esl.Connection(self.config.fsw.host, self.config.fsw.port, self.config.fsw.password, function() { | ||
//listen to ALL events, and ask for them to be json encoded | ||
self.fsw.subscribe(function(evt) { | ||
self._configure(); | ||
self._init(); | ||
}); | ||
}); | ||
|
||
self.fsw.on('esl::event::*', function(evt) { | ||
console.log('Event:', evt); | ||
}); | ||
|
||
self.fsw.on('esl::event::MESSAGE', function(evt) { | ||
var n = evt.getHeader('from_user'), | ||
seq = parseInt(evt.getHeader('Event-Sequence'), 10); | ||
|
||
//with action="fire" in the chatplan, you sometimes | ||
//will get the message 2 times O.o | ||
if(seq <= self.lastSeq) return; | ||
|
||
self.lastSeq = seq; | ||
|
||
if(self.clients[n]) { | ||
self.clients[n].emit('recvmsg', evt.getBody()); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "chatty", | ||
"version": "0.0.1", | ||
"description": "Real-Time Chat application to talk to Phones via SMS", | ||
"author": "Chad Engler <Chad.Engler@patlive.com>", | ||
"homepage": "https://github.patlive.local/Chad-Engler/chatty", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.patlive.local/Chad-Engler/node-esl.git" | ||
}, | ||
"dependencies": { | ||
"utile": "git+https://github.com/englercj/utile.git", | ||
"modesl": "git+https://github.patlive.local/Chad-Engler/node-esl.git", | ||
"express": "3.x", | ||
"socket.io": "0.9.x" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.x" | ||
}, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#chat { display:none; } | ||
|
||
.clear { clear:both; } | ||
|
||
#msgtxt { | ||
margin:10px 0 0 0; | ||
font-size:1.3em; | ||
color:#333; | ||
} | ||
|
||
#btnSend { | ||
font-size:1.3em; | ||
} | ||
|
||
|
||
.msg { | ||
width:500px; | ||
min-height:15px; | ||
|
||
padding:5px; | ||
|
||
border-radius:3px; | ||
border:solid 1px #CCC; | ||
|
||
margin:5px 0 0 20px; | ||
|
||
background: #f2f6f8; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f2f6f8), color-stop(50%,#d8e1e7), color-stop(51%,#b5c6d0), color-stop(100%,#e0eff9)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%); /* Opera 11.10+ */ | ||
background: -ms-linear-gradient(top, #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%); /* IE10+ */ | ||
background: linear-gradient(to bottom, #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%); /* W3C */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f6f8', endColorstr='#e0eff9',GradientType=0 ); /* IE6-9 */ | ||
} | ||
|
||
.msg .icon { width:32px; height:32px; background:center center Transparent no-repeat; float:left; } | ||
|
||
.msg.sending .icon { background:url(../img/sending_32.png); } | ||
.msg.sent .icon { background:url(../img/send_32.png); } | ||
.msg.recv .icon { background:url(../img/recv_32.png); } | ||
.msg.failed .icon { background:url(../img/failed_32.png); } | ||
|
||
.msg .txt { float:left; margin-left:10px; width:90%; } | ||
|
||
|
||
.msg.sending { opacity:0.4; } | ||
.msg.sent { | ||
background: #e4f5fc; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #e4f5fc 0%, #bfe8f9 50%, #9fd8ef 51%, #2ab0ed 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e4f5fc), color-stop(50%,#bfe8f9), color-stop(51%,#9fd8ef), color-stop(100%,#2ab0ed)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #e4f5fc 0%,#bfe8f9 50%,#9fd8ef 51%,#2ab0ed 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #e4f5fc 0%,#bfe8f9 50%,#9fd8ef 51%,#2ab0ed 100%); /* Opera 11.10+ */ | ||
background: -ms-linear-gradient(top, #e4f5fc 0%,#bfe8f9 50%,#9fd8ef 51%,#2ab0ed 100%); /* IE10+ */ | ||
background: linear-gradient(to bottom, #e4f5fc 0%,#bfe8f9 50%,#9fd8ef 51%,#2ab0ed 100%); /* W3C */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e4f5fc', endColorstr='#2ab0ed',GradientType=0 ); /* IE6-9 */ | ||
} | ||
.msg.recv { | ||
margin:5px 20px 0 0; | ||
|
||
background: #9dd53a; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera 11.10+ */ | ||
background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */ | ||
background: linear-gradient(to bottom, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */ | ||
} | ||
.msg.failed { | ||
border:solid 1px #FF0000; | ||
|
||
background: #f85032; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #f85032 0%, #f16f5c 50%, #f6290c 51%, #f02f17 71%, #e73827 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f85032), color-stop(50%,#f16f5c), color-stop(51%,#f6290c), color-stop(71%,#f02f17), color-stop(100%,#e73827)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%); /* Opera 11.10+ */ | ||
background: -ms-linear-gradient(top, #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%); /* IE10+ */ | ||
background: linear-gradient(to bottom, #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%); /* W3C */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f85032', endColorstr='#e73827',GradientType=0 ); /* IE6-9 */ | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Chatty</title> | ||
|
||
<!-- Meta --> | ||
<meta charset="utf-8" /> | ||
|
||
<!-- CSS --> | ||
<link rel="stylesheet" href="/css/main.css" /> | ||
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css" /> | ||
|
||
<!-- JS --> | ||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> | ||
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script src="/js/app.js"></script> | ||
</head> | ||
<body> | ||
<div id="num"> | ||
<fieldset> | ||
<legend>Number</legend> | ||
|
||
( <input id="areacode" class="num" type="text" size="3" maxlength="3" /> ) | ||
<input id="phnum1" class="num" type="text" size="3" maxlength="3" /> - | ||
<input id="phnum2" class="num" type="text" size="4" maxlength="4" /> | ||
</fieldset> | ||
|
||
<button id="btnConnect">Open Chat</button> | ||
</div> | ||
|
||
<div id="chat"> | ||
<div id="messages"> | ||
|
||
</div> | ||
<input id="msgtxt" type="text" /> | ||
<button id="btnSend">Send</button> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.