install kontalk bot / errbot on rpi2 [raspberrypi2]

THIS INSTRUCTION IS OUTDATED:
new instruction at:
https://github.com/freddii/kontalkpi

based on:
http://errbot.io/en/latest/user_guide/administration.html#configuration
http://errbot.io/en/latest/_downloads/config-template.py
http://errbot.io/en/latest/user_guide/configuration/xmpp.html
https://github.com/fritzy/SleekXMPP/issues/250
https://fredfire1.wordpress.com/2015/07/09/install-kontalk-on-debian-debian/

this tutorial is for the raspberry pi 2:
https://www.amazon.de/Raspberry-Pi-quad-core-Cortex-A7-compatibility/dp/B00T2U7R7I

1) create two kontalk accounts
2) prepare the sd card
3) install the kontalk bridge
4) install errbot (a xmpp jabber bot based on SleekXMPP)
5) configure errbot
6) run errbot
7) automatic start kontalk on boot
8) optional (test more errbot plugins)
9) check the log

1)create two kontalk accounts: to make the instruction simple you will need two mobilephones with different phone numbers
i will call them “phone-1” and “phone-2”

1.1) phone-1: you only need this phone to export the kontalk account from the phone and import it to the raspberrypi
to export the kontalk account from phone:
in the app:
menu > settings > service > export personal key (you will then end up with a kontalk-keys.zip file
also note the BOT_LongHASH of phone-1: you find it in the android app (menu > my personal key) it is the hash infront of “@beta.kontalk.net”
then deinstall kontalk on phone-1

1.2) phone-2: private mobile phone to remote control the bot
also note the USER_LongHASH of phone-2: you find it in the android app (menu > my personal key) it is the hash infront of “@beta.kontalk.net”

2) prepare the sd card:
download raspbian-jessie-lite image
#wget http://vx2-downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2016-05-31/2016-05-27-raspbian-jessie-lite.zip
cd ~
wget http://downloads.raspberrypi.org/raspbian_lite_latest -O raspbian_lite_latest.zip
unzip raspbian_lite_latest.zip

write the image to a sd card
login with ssh (username=pi password=raspberry)

sudo apt update && sudo apt upgrade

sudo reboot

3) install the kontalk bridge:
create a kontalk folder:
cd
mkdir kontalk
cd ~/kontalk/

copy over the kontalk-keys.zip to ~/kontalk/

unzip the file:
cd ~/kontalk/
unzip kontalk-keys.zip -d /$HOME/kontalk/
#rm kontalk-keys.zip

download the bridge:
cd ~/kontalk/
wget https://raw.githubusercontent.com/kontalk/client-adapters/master/tunnel/ssl_bridge.py
chmod 755 ssl_bridge.py

install dependencies for the bridge:

sudo apt install python-pip
sudo pip install --upgrade pip
#from pip_1.5.6 to 8.1

sudo apt install gcc libffi-dev python-dev

sudo pip install twisted

#sudo pip install six pyopenssl

sudo pip install service_identity

test the bridge:
cd ~/kontalk/
./ssl_bridge.py -d -p 5224 --domain beta.kontalk.net -c kontalk-login.crt -k kontalk-login.key beta.kontalk.net:5222

then quit the bridge with ctrl +c

4) install errbot(for python2):
sudo pip install errbot #takes long

mkdir ~/errbot; cd ~/errbot
errbot --init


test the bot:
cd ~/errbot; errbot

then quit the bot with:
!shutdown --confirm

install dependencies for xmpp for the bot:
sudo pip install "errbot[XMPP]"
sudo pip install sleekxmpp

4) install errbot(for python3):
i tryed it this way cause i just wanted to make it running,
better try it yourself with virtualenv
http://errbot.io/en/latest/user_guide/setup.html

sudo apt install python3-pip

sudo pip3 install --upgrade pip

sudo apt-get install libssl-dev

sudo pip3 install errbot

mkdir ~/errbot; cd ~/errbot
errbot --init

test the bot:
cd ~/errbot; errbot

then quit the bot with:
!shutdown --confirm

install dependencies for xmpp for the bot:
sudo pip3 install "errbot[XMPP]"
sudo pip3 install sleekxmpp

5) configure the errbot
edit the config.py:
nano ~/errbot/config.py
change
BACKEND = 'Text'
to:
BACKEND = 'XMPP'

and
BOT_ADMINS = ('change me', )
to:
BOT_ADMINS = ('USER_LongHASH@beta.kontalk.net', )
change USER_LongHASH to the hash you noted before

and add at the end of the file:

BACKEND = 'XMPP'
BOT_ADMINS = ('USER_LongHASH@beta.kontalk.net', )

BOT_IDENTITY = {
    'username': 'BOT_LongHASH@beta.kontalk.net',  # The JID of the user you have created for the bot
    'password': '1234',        # The corresponding password for this user
    'server': ('localhost',5224), # server override
}

XMPP_FEATURE_MECHANISMS = {'use_mech': 'PLAIN', 'unencrypted_plain': True, 'encrypted_plain': False}

#AUTOINSTALL_DEPS = True

change USER_LongHASH and BOT_LongHASH to the hashes you noted before

6) run errbot:
you have to run the BRIDGE in BACKGROUND with screen BEFORE you can start the ERRBOT with the changed settings:

install screen:
sudo apt install screen

run the bridge in background:
screen -dmS longrun_bridge sh -c 'cd ~/kontalk/;./ssl_bridge.py -d -p 5224 --domain beta.kontalk.net -c kontalk-login.crt -k kontalk-login.key beta.kontalk.net:5222'

just for info:
screen -r #to resume screen session
ctrl+a + d #to detach screen session

now run errbot in background:
screen -dmS longrun_errbot sh -c 'cd ~/errbot/;errbot'

test with smartphone:
in the android app:
settings > message-settings > privacy-settings > [] encrypt messages (disable encryption on kontalk)
settings > message-settings > privacy-settings > [] send “writing” notifications (disable notifications for writing)

write in the android app from phone-2 (your private mobile phone to remote control the bot) to the bot:
!help
!about
!uptime
!shutdown --confirm

..

7) automatic start kontalk on boot:
crontab -e

@reboot screen -dmS longrun_bridge sh -c 'cd ~/kontalk/;./ssl_bridge.py -d -p 5224 --domain beta.kontalk.net -c kontalk-login.crt -k kontalk-login.key beta.kontalk.net:5222' && sleep 10 && screen -dmS longrun_errbot sh -c 'cd ~/errbot/;/usr/local/bin/errbot'

8) optional (test more errbot plugins):
based on:
https://github.com/errbotio/errbot/wiki
sudo apt install git-core #install git-core to be able to use more plugins
all plugins will be located in:
~/errbot/data/plugins

install plugin err-time(https://github.com/gbin/err-time):
install dependencies:
sudo pip3 install pytz
to install the plugin write from your phone to the bot:
!repos install gbin/err-time
usage of the plugin:
!time moscow

install plugin err-rando:
to install the plugin write from your phone to the bot:
!repos install https://github.com/samueldg/err-rando
usage of the plugin:
!diceroll
!cointoss

install plugin err-secondlife:
install dependencies:
sudo pip3 install mechanize
to install the plugin write from your phone to the bot:
!repos install https://github.com/zoni/err-secondlife

install plugin err-wikipedia:
install dependencies:
sudo pip3 install wikipedia
to install the plugin write from your phone to the bot:
!repos install https://github.com/Djiit/err-wikipedia
!plugin config Wikipedia {'LANGUAGE': 'de', 'SUMMARY_MAX_LENGTH': 255}

usage:
!describe Roboter
!describe your_own_word

install plugin err-imagebot(https://github.com/errbotio/err-imagebot):
install dependencies:
sudo pip3 install feedparser
sudo apt install libxml2-dev
sudo apt install python-lxml
sudo apt install libxml2-dev
sudo apt install libxslt1-dev
sudo pip3 install lxml

to install the plugin write from your phone to the bot:
!repos install errbotio/err-imagebot
usage:
first restart the bot:
!restart
then you can use it:
!fp
!animals

to uninstall it:
!repos uninstall errbotio/err-imagebot

install plugin err-ascii-art(https://github.com/errbotio/err-ascii-art):
install dependencies:
sudo pip3 install pyfiglet
to install the plugin write from your phone to the bot:
!repos install errbotio/err-ascii-art
to uninstall it:
!repos uninstall errbotio/err-ascii-art

install plugin err-cards-tester(https://github.com/errbotio/err-cards-tester):
to install the plugin write from your phone to the bot:
!repos install errbotio/err-cards-tester
to uninstall it:
!repos uninstall errbotio/err-cards-tester

install plugin err-camera:
install dependencies:
sudo pip3 install rpio
sudo apt install python-rpio python3-rpi.gpio

to install the plugin write from your phone to the bot:
!repos install https://github.com/fernand0/err-camera

install plugin err-hello:
to install the plugin write from your phone to the bot:
!repos install https://github.com/alimac/err-hello

install plugin err-reminders(https://github.com/kdknowlton/err-reminders):
install dependencies:
sudo pip3 install parsedatetime
to install the plugin write from your phone to the bot:
!repos install kdknowlton/err-reminders
usage:
!remind me tomorrow 11:00 -> Cook coffee.
!remind me today 12:00 -> make meal

install plugin err-quote(https://github.com/Betriebsrat/err-quote):
to install the plugin write from your phone to the bot:
!repos install Betriebsrat/err-quote

9) check the log
to check the log with nano:
nano ~/errbot/errbot.log

other bot ideas:
https://storebot.me/
http://botsfortelegram.com/
http://telegramgeeks.com/2015/09/top-10-bots/
https://storebot.me/bot/umotionsbot

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s