Sevabot Skype Bot
Sevabot Skype Bot
Sevabot Skype Bot
Release 1.0
Contents
13
17
19
Chat commands
23
27
Troubleshooting
39
43
Trademark notice
45
ii
Contents
Contents
CHAPTER 1
Introduction
Installing Skype and xvfb
Setting up Skype and remote VNC
Installing Sevabot
Running sevabot
Test it
Testing HTTP interface
Troubleshooting
Running sevabot as service
Setting avatar image
Installing on Ubuntu desktop
1.1 Introduction
There instructions are for setting up a headless (no monitor attached) Sevabot running in Skype on Ubuntu Server. The
instructions have tested on Ubuntu Version 12.04.1 unless mentioned otherwise.
Note: For desktop installation instructions see below.
apt-get update
apt-get install -y xvfb fluxbox x11vnc dbus libasound2 libqt4-dbus libqt4-network libqtcore4 libqtgui
wget http://www.skype.com/go/getskype-linux-beta-ubuntu-64 -O skype-linux-beta.deb
# if there are other unresolved dependencies install missing packages using apt-get install and then
dpkg -i skype-linux-beta.deb
Get Sevabot:
git clone git://github.com/opensourcehacker/sevabot.git
Note: If you want to live dangerously you can use git dev branch where all the development happen. You can switch
to this branch with git checkout dev command in the sevabot folder.
Start xvfb, fluxbox and Skype:
# This will output some Xvfb warnings to the terminal for a while
SERVICES="xvfb fluxbox skype" ~/sevabot/scripts/start-server.sh start
On your local computer start the VNC viewing software and connect the server:
vncviewer yourserver.example.com
You see the remote desktop. Login to Skype for the first time. Make Skype to save your username and password.
Create Skype account in this point if you dont have one for sevabot.
Now, in your local Skype, invite the bot as your friend. Then accept the friend request.
Note: It is important to add one Skype buddy for your Sevabot instance in this point, so dont forget to do this step.
Now, in Sevabot go to Skypes settings and set the following:
No chat history
Only people on my list can write me
Only people on my list can call me
Deploy sevabot, as checked out from Github earlier, using Python virtualenv:
cd sevabot
virtualenv venv
. venv/bin/activate
python setup.py develop
ALTERNATIVE on some older Ubuntus - do only if the virtualenv and pip installation above doesnt seem to work:
cd sevabot curl -L -o virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py python
virtualenv.py venv . venv/bin/activate . venv/bin/activate
This will
Pull all Python package dependencies from pypi.python.org package service
Create Sevabot launch scripts under ~/sevabot/venv/bin/
Set password and customize other Sevabot settings by creating and editing editing settings.py:
In settings.py set
SHARED_SECRET: web interface password
HTTP_HOST: Public IP address you want Sevabots web interface listen to (on Ubuntu you can figure this out
using ipconfig command)
We need one more thing and thats accepting Skype dialog for Sevabot control in VNC session. Make sure Xvfb,
Fluxbox, Skype and VNC is running as instructed above. Do:
# Start Sevabot and make initial connect attempt to Skype
SERVICES=sevabot ~/sevabot/scripts/start-server.sh start
* Running on http://123.123.123.123:5000/
tail -f ~/sevabot/logs/sevabot.log
1.6 Test it
Start chatting with your Sevabot instance with your local Skype.
In Skype chat, type:
!ping
Note: Sometimes Skype starts up slowly on the server and the initial messages are eaten by something. If you dont
get instant reply, wait one minute and type !ping again.
1.8 Troubleshooting
If you have problems see Troubleshooting section for more information how to resolve them.
1.8. Troubleshooting
Example:
scripts/start-server.sh stop
...
scripts/start-server.sh start
...
scripts/start-server.sh status
Xvfb is running
fluxbox is running
skype is running
Sevabot running
OVERALL STATUS: OK
To run sevabot from the server from reboot or do a full bot restart there is an example script reboot-seva.sh provided.
It also does optionally manual SSH key authorization so that the bot can execute remote commands over SSH.
To make your Sevabot bullet-proof add a cron job to check that Sevabot is running correctly and reboot if necessary.
Start VNC:
sevabot/scripts/start-vnc.sh start
10
apt-get install xvfb fluxbox x11vnc dbus libasound2 libqt4-dbus libqt4-network libqtcore4 libqtgui4 l
apt-get install python-gobject-2 curl git
wget http://www.skype.com/go/getskype-linux-beta-ubuntu-64 -O skype-linux-beta.deb
# if there are other unresolved dependencies install missing packages using apt-get install and then
dpkg -i skype-linux-beta.deb
11
exit
Start Skype normally, register a new user or you can also use your own Skype account for testing..
Install Sevabot:
git clone git://github.com/opensourcehacker/sevabot.git
cd sevabot
virtualenv venv # Assume we use Python 2.7 virtualenv installed from Ubuntu 12.04 package manager
. venv/bin/activate
python setup.py develop
Use your text editor to open settings.py and set your own password there.
Start sevabot:
. venv/bin/activate
sevabot
12
CHAPTER 2
Introduction
Installing Skype
Installing sevabot
Set password and other settings
Running sevabot
Test it
Testing HTTP interface
2.1 Introduction
There instructions are for setting up a Sevabot to run on OSX desktop.
These instructions are mostly useful for Sevabot development and testing and not for actual production deployments.
This will
Pull all Python package dependencies from pypi.python.org
13
Setup your Skype admin username and HTTP interface password by editing settings.py.
When you launch it for the first time you need to accept the confirmation dialog in the desktop environment (over
VNC on the server).
or which ever display youre running your skype on your server.
Note: There might be a lot of logging and stdout output when the bot starts and scans all the chats of running Skype
instance.
Eventually you see in the console:
Running on http://127.0.0.1:5000/
2.6 Test it
In Skype chat, type:
!ping
Just access the Sevabot server by going with your web browser to:
http://localhost:5000
15
16
CHAPTER 3
Introduction
Vagrant it
3.1 Introduction
Vagrant is a tool to setup and deploy local virtual machines easily. Sevabot has a script for creating Vagrant deployments.
3.2 Vagrant it
Here is deployment instructions for deployment and automatic virtual machine configuration:
git clone https://github.com/opensourcehacker/sevabot.git
cd sevabot
vagrant box add precise64 http://files.vagrantup.com/precise64.box
vagrant up
Now you should have a virtual machine running having a runnign Sevabot in it.
TODO (these instructions might need someone to have a look of them as I dont use Vagrant myself -MIkko)
17
18
CHAPTER 4
Introduction
Installing Skype
Installing Python
Installing sevabot
Set password and other settings
Running sevabot
Test it
Testing HTTP interface
4.1 Introduction
There instructions are for setting up a Sevabot to run on Windows
These instructions are mostly useful for Sevabot development and testing and not for actual production deployments.
19
This will
Pull all Python package dependencies from pypi.python.org
Create a scripts under venv/bin/ to run Sevabot
Note: If you want to live dangerously you can use git dev branch where all the development happen.
Setup your Skype admin username and HTTP interface password by editing settings.py.
When you launch it for the first time you need to accept the confirmation dialog in the desktop environment
Note: There might be a lot of logging and stdout output when the bot starts and scans all the chats of running Skype
instance.
Eventually you see in the console:
Running on http://127.0.0.1:5000/
20
4.7 Test it
In Skype chat, type:
!ping
4.7. Test it
21
22
CHAPTER 5
Chat commands
Introduction
Out of the box commands
Creating custom commands
Stateful modules
Running commands on remote servers
5.1 Introduction
Sevabot supports commands you can type into group chat. All commands begin with !.
You can create your own commands easily as Sevabot happily executes any UNIX executable script.
23
Add UNIX execution bit on the script using chmod u+x myscript.sh
In Sevabot chat, type command !reload to relaod all scripts
Now you should see command !myscript in the command list
The following environment variables are exposed to scripts SKYPE_USERNAME, SKYPE_FULLNAME from the
person who executed the command
You you need to install SSH keys on skype user to contact these servers:
ssh -a skype@sevabotserver.example.com
# Create key for the bot if one doesn't exist in .ssh/id_rsa
# Note: For safety reasons set passpharse. See reboot-seva script
# how passphrase enabled key is handled
ssh-keygen
# Copy the key to the remote server where you indent to run SSH commands
ssh-copy-id targetuser@targetserver.com
25
26
CHAPTER 6
Introduction
Supported services and examples
Getting chat list
Sending a message over HTTP interface
Timed messages
6.1 Introduction
Sevabot webhooks is a way to send Skype messages from external services using HTTP GET and POST requests.
Because there is no webhook standard Sevabot supports different ways to parse HTTP message payloads
Signed and unsigned messages: shared secret MD5 signature prevents sending messages from hostile services
HTTP GET and HTTP POST requests
Service specific JSON payloads
To send a message to a chat you must first know to to the id of a group chat. Sevabot server HTTP interface has a page
to show this list (see below).
Introduction
These examples use an out-dated web API. Until the documentation is properly updated, you can post a message with
the following commandline:
27
Introduction
Here is an example how to send messages to Skype chat from external Python scripts and services. They do not need
to be Sevabot commands, messages are send over HTTP interface.
Sending messages from separate URL thread
socket
threading
urllib
urllib2
logging
28
r = urllib2.urlopen(self.url, self.data)
r.read()
except Exception as e:
logger.error(e)
logger.exception(e)
finally:
socket.setdefaulttimeout(orignal_timeout)
Introduction
zapier.com offers free mix-and-match different event sources to different triggers. The event sources includes popular
services like Github, Dropbox, Salesforce, etc.
Zapier Web hooks (raw HTTP POSTs)
Zapier hook reads HTTP POST data variable payload to chat message as is. It is useful for other integrations as well.
You need to register your zap in zapier.com
Sevabot offers support for Zapier web hook HTTP POST requests
Create a zap in zapier.com. Register. Add Webhooks URL with your bot info:
http://yourserver.com:5000/message_unsigned/
by {{user__login}} - {{html_url}}
29
You can use curl to test the hook from your server, for firewall issues and such:
30
Introduction
Commit notifications
Pull request notifications
Issue notifications
Introduction
Github notifications are provided through natively through Github and via Zapier middleman service.
Commit notifications
Sevabot has built-in support for Github post-receive commit notifications.
To add one
You need to be the repository admin
Go Admin > Service hooks on Github
Add Webhooks URL with your bot info:
http://yourserver.com:5000/github-post-commit/CHATID/SHAREDSECRET/
Save
Now you can use Test hook button to send a test message to the chat
Following commits should come automatically to the chat
Pull request notifications
Sevabot has built-in support for Github post-receive pull request notifications.
To add one
You need to be the repository admin
Go Admin > Service hooks on Github
Add Webhooks URL with your bot info:
http://yourserver.com:5000/github-pull-request/CHATID/SHAREDSECRET/
Save
Using curl and GitHub API edit the above webhook by using the PATCH verb and JSON string of {active:true,add_events:[pull_request]}
See http://developer.github.com/v3/repos/hooks/ for more details on webhook editing through the
GitHub API
Whenever new pull requests are opened or closed a notification should come automatically to the chat
Issue notifications
Use Zapier webhook as described below.
This applies for
New Github issues
New Github comments
See generic Zapier instructions how to set-up the hook.
31
Introduction
Use the provided shell script example how to install a post-receive hook on your SVN server to send commit notifications to Skype.
Introduction
Jenkins is a popular open source continuous integration server.
Jenkins supports webhook notifications
ci.org/display/JENKINS/Notification+Plugin
by
using
the
Notification
plugin:
https://wiki.jenkins-
for example:
http://sevabot.example.com:5000/jenkins-
32
Introduction
TeamCity <http://www.jetbrains.com/teamcity/> is a popular continuous integration server from JetBrains.
TeamCity
supports
webhook
notifications
http://tcplugins.sourceforge.net/info/tcWebHooks
by
using
the
tcWebHooks
plugin:
Setting up a webhook
Install the plugin as directed in the link below http://sourceforge.net/apps/trac/tcplugins/wiki/TcWebHooks
Then in TeamCity, for each project you want to send notifications for, under the Web Hooks section, click Edit
Project Web Hooks then click on + Click to create new WebHook for this project
Enter your sevabot unsigned message notification endpoint, for example:
http://yourserver.com:5000/message_unsigned/
Trailing slash is important.
The followning Web Hook Payload Format setting must be used: Name Value Pairs
Go to sevabot web interface and http://yourserver.com:5000/ get chat id from Skype
On TeamCity server edit the ${HOME}/.BuildServer/config/{ProjectName}/plugin-settings.xml file and add the following after the closing tag of your webhook state tag i.e. </states>.
<parameters> <param name="chat_id" value="{SkypeChatID}" /> </parameters>
When a TeamCity build under this project completes, you should see the bot emit a message with the build status.
Introduction
Zabbix is a popular open source monitoring solution.
You can get Zabbix monitoring alerts like server down, disk near full, etc. to Skype with Sevabot.
Setting up a webhook
First you need to configure Media for your Zabbix user. The default user is called Admin.
Go to Administrator > Media types.
Add new media Skype with Script name send.sh.
Go to Administrator > Users > Admin. Open Media tab. Enable media Skype for this user. In the Send to parameter
put in your chat id (see instructions above).
On the server running the Zabbix server process create a file /usr/local/share/zabbix/alertscripts/send.sh:
33
#!/bin/bash
#
# Example shell script for sending a message into sevabot
#
# Give command line parameters [chat id] and [message].
# The message is md5 signed with a shared secret specified in settings.py
# Then we use curl do to the request to sevabot HTTP interface.
#
#
# Chat id comes as Send To parameter from Zabbix
chat=$1
# Message is the second parameter
msg=$2
# Our Skype bot shared secret
secret="xxx"
# The Skype bot HTTP msg interface
msgaddress="http://yourserver.com:5000/msg/"
md5=`echo -n "$chat$msg$secret" | md5sum`
#md5sum prints a '-' to the end. Let's get rid of that.
for m in $md5; do
break
done
curl $msgaddress -d "chat=$chat&msg=$msg&md5=$m"
width 500px
Note:
Depending on the UNIX user home the touch file may be /var/run/zabbix/zabbix_test or
/home/zabbix/zabbix_test You might need to manualy switch Item state to Enabled after fixing this.
Example trigger:
34
Then the script we give to Sevabot to poke the file over SSH to generate Information notification in Zabbix and getting
this notification back to our Zabbix monitoring Skype chat, confirming the agent is alive and well.
agents.sh:
#!/bin/bash
#
# Detect if we have a public key available
ssh-add -L > /dev/null
if [[ $? != "0" ]] ; then
echo "Log-in as sevabot UNIX user and authorize SSH key"
exit 1
fi
# Get list of hosts from SSH config file
HOSTS=`grep "Host " ~/.ssh/config | awk '{print $2}'`
# If some hosts don't have zabbix agents running, there's no need to use this script for them.
# Add this line to ~/.ssh/config:
# #NoAgents host1 host2
NOAGENT=`grep "#NoAgents " ~/.ssh/config | cut -d' ' -f2- | tr ' ' '\n'`
if [ -n "$NOAGENT" ]; then
HOSTS=`echo -e "$HOSTS\n$NOAGENT" | sort | uniq -u`
fi
35
errors=0
# On each server touch a file to change its timestamp
# Zabbix monitoring system will detect this and
# report the alert back to Skype chat via a hook
for h in $HOSTS; do
ssh -o "PasswordAuthentication no" $h "touch -m zabbix_test"
if [[ $? != "0" ]] ; then
echo "Failed to SSH to $h as sevabot UNIX user"
errors=1
fi
done
if [[ $errors == "0" ]] ; then
echo "Succesfully generated zabbix_test ping on all servers"
fi
Example ~/.ssh/config:
Host xxx
User zabbix
Hostname xxx.twinapex.fi
Host yyy
User zabbix
Hostname yyy.twinapex.fi
Please note that you need to set up bot SSH keys for this.
Diagnosing
If none of the agents is not replying your Zabbix host is probably messed up,
/etc/init.d/zabbix-server restart
reboot it:
It will return a HTTP page containing a list of Sevabot internal chat ids.
36
37
38
CHAPTER 7
Troubleshooting
Logging
Double messages
Segfaults
Skype4Py distribution for OSX
Skype messages not coming through to bot interface
Crashing on a startup on Ubuntu server
Sevabot ignores commands and logs hang in sevabot - DEBUG - Attaching to Skype
7.1 Logging
By default, Sevabot writes logging output to file logs/sevabot.log.
You can watch this log in real time with UNIX command:
tail -f logs/sevabot.log
7.3 Segfaults
If you get segfault on OSX make sure you are using 32-bit Python.
Debugging segmentation faults with Python.
39
40
Chapter 7. Troubleshooting
export DISPLAY=:1
or:
export DISPLAY=:0
7.7 Sevabot ignores commands and logs hang in sevabot - DEBUG Attaching to Skype
This concerns only Ubuntu headless server deployments.
Your fluxbox might have hung. Kill it with fire:
killall -SIGKILL fluxbox
Restart.
7.7. Sevabot ignores commands and logs hang in sevabot - DEBUG - Attaching to Skype
41
42
Chapter 7. Troubleshooting
CHAPTER 8
Introduction
IRC
Support tickets and issues
Installing development version
Debugging
Contributions
Releases
8.1 Introduction
How to participate to the spectacular future of Sevabot. You can make the life of Sevabot better - and yours too!
8.2 IRC
For chatting
/join #opensourcehacker @ irc.freenode.net
Note: due to low activity of the channel prepare to idle there for 24 hours to wait for the answer.
43
8.5 Debugging
You might want to turn on DEBUG_HTTP setting to dump out incoming HTTP requests if you are testing / developing
your own hooks.
8.6 Contributions
All contributions must come with accompaning documentation updates.
All Python files must follow PEP-8 coding conventionas and be flake8 valid.
Submit pull request at Github.
For any changes update CHANGES.rst.
8.7 Releases
Use zest.releaser
See Github for more project information.
44
CHAPTER 9
Trademark notice
The Skype name, associated trade marks and logos and the S logo are trade marks of Skype or related entities.
Sevabot is an open source project and not associate of Microsoft Corporation or Skype.
45