Welcome to listenclosely’s documentation!¶
Contents:
listenclosely¶
CI:
PyPI:
Docs:
Listenclosely is a django-app that works as a middleman to connect instant messaging clients. Think on a Call Center/Customer Service using using instant messaging... exactly what it does.
- It is simple, connects Askers with online Agents until the Chat is considered as terminated and the Agent is released to attend other Asker chats.
- It is flexible, so you can define your own strategies to assign Agents to Askers and your own messaging backend services.
Messaging Services integrated:
Documentation¶
The full documentation is at https://listenclosely.readthedocs.org.

- Asker1 is chatting with the Busy Agent
- Asker2 try to chat but no free Agent was free so is waiting with a Pending chat to be attended by an agent
- Asker3 is opening a chat and Online Agent will be assigned to the chat
Quickstart¶
Install listenclosely:
pip install listenclosely
Then use it in a project:
import listenclosely
Add it to django apps and migrate:
INSTALLED_APPS = [
...
'listenclosely',
...
]
python manage.py migrate
Select, install and configure service backend
LISTENCLOSELY_MESSAGE_SERVICE_BACKEND = "listenclosely_telegram.service.TelegramMessageServiceBackend"
Define your agent strategy or define your own:
LISTENCLOSELY_AGENT_STRATEGY = 'listenclosely.strategies.first_free.FirstFreeAgentStrategy'
Add step to your celery app:
from listenclosely.celery import ListenCloselyAppStep
app.steps['worker'].add(ListenCloselyAppStep)
Start your celery app usign gevent:
celery --app=demo_app.celery:app worker -P gevent
Call listen task or define a celery scheduler to execute:
from listenclosely import tasks
tasks.listen.delay()
Features¶
- Connects Askers and Agents in chats to establish a Chat
- Strategies to find Agent to attend new Asker chat. Define your own strategies
- Messaging Service Backend: Define your own messaging service backend implementations.
- Cron tasks for attending pending chats and to terminate obsolete chats to release Agents
Running Tests¶
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements/test.txt
(myenv) $ make test
Installation¶
At the command line:
$ pip install listenclosely
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv listenclosely
$ pip install listenclosely
Usage¶
Then use it in a project:
import listenclosely
Add it to django apps and migrate:
INSTALLED_APPS = [
...
'listenclosely',
...
]
python manage.py migrate
Select, install and configure service backend
LISTENCLOSELY_MESSAGE_SERVICE_BACKEND = "listenclosely_telegram.service.TelegramMessageServiceBackend"
Define your agent strategy or define your own:
LISTENCLOSELY_AGENT_STRATEGY = 'listenclosely.strategies.first_free.FirstFreeAgentStrategy'
Add step to your celery app:
from listenclosely.celery import ListenCloselyAppStep
app.steps['worker'].add(ListenCloselyAppStep)
Start your celery app usign gevent:
celery --app=demo_app.celery:app worker -P gevent
Call listen task or define a celery scheduler to execute:
from listenclosely import tasks
tasks.listen.delay()
NOTE: listenclosely comes with a demo with celery configuration example.
How it works¶

- Asker1 is chatting with the Busy Agent
- Asker2 try to chat but no free Agent was free so is waiting with a Pending chat to be attended by an agent
- Asker3 is opening a chat and Online Agent will be assigned to the chat
State machines of Agent and Chat:


Customization¶
Listenclosely is easy to be customized with your own requirements
Agent stategy¶
Just extend strategies.base.BaseAgentStrategy and define your own free_agent function:
class FirstFreeAgentStrategy(BaseAgentStrategy):
"""
Choose first free agent
"""
def free_agent(self):
free_agents = Agent.online.all()
if free_agents:
return free_agents[0]
return None
Then configure settings:
LISTENCLOSELY_AGENT_STRATEGY = 'your_strategy.YourAgentStrategy'
Message Service Backend¶
Extend services.base.BaseMessageServiceBackend. You must implement some methods:
def listen(self):
"""
Connect to service and listen for receive messages.
To implement in concrete services
"""
raise NotImplementedError('subclasses of BaseMessageServiceBackend must override listen() method')
def send_message(self, id_service, content):
"""
Send message to a instant messages service
To implement in concrete services
:rtype string message_id: identifier for message service
"""
raise NotImplementedError('subclasses of BaseMessageServiceBackend must override send_message() method')
def disconnect(self):
"""
Disconnect to service.
To implement in concrete services
"""
raise NotImplementedError('subclasses of BaseMessageServiceBackend must override disconnect() method')
- Use other services as example. At the moment:
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/jlmadurga/listenclosely/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
listenclosely could always use more documentation, whether as part of the official listenclosely docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/jlmadurga/listenclosely/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up listenclosely for local development.
Fork the listenclosely repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/listenclosely.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv listenclosely $ cd listenclosely/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 listenclosely tests
$ python setup.py test
$ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/jlmadurga/listenclosely/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Juan Madurga <jlmadurga@gmail.com>
Contributors¶
None yet. Why not be the first?