Until now, Slack and Pepper have been linked using Slack's Incoming Web Hook. I was posting using the request module from the work app, I wanted to be able to receive notifications from the Slack side, so I thought about installing SlackBot in Pepper.
What I wanted to do with SlackBot.
--Create a channel that collects Pepper bots. --Send various events to Pepper with a message addressed to the bot. --Send various events to all Pepper with a message addressed to @Channel. --Collect various sensor information of Pepper in Slack.
Also, I wanted to use it across the board regardless of the work application, so I implemented it as a service by referring to this article. http://qiita.com/yacchin1205/items/11301d79380d08d2dbf6
Mac OS Sierra Python 2.7.10
pip install qibuild
Please drop the following version instead of the latest version. The latest version (2.5.5 at the time of writing) seems to have many changes, and there was little information to be helpful, so I downloaded 2.4.3.
pynaoqi-python2.7-2.4.3.28-mac64
Leave it through path. Also, add it to .bash_profile.
$ export PYTHONPATH=${PYTHONPATH}:/path/to/pynaoqi-python2.7-2.4.3.28-mac64
$ export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/path/to/pynaoqi-python2.7-2.4.3.28-mac64
The following commands can be used if the path is correct.
$ python
>> import qi
>> import naoqi
The final required environment is as follows.
SlackBotService
qiproject.xml
manifest.xml
slackbotservice.py
slackbotservice.pml
bot_settings.py
lib
backports
slackbot
slacker
websocket
six.py
plugins
__init__.py
mention.py
proxy.py
Execute the following command in the same hierarchy as the project directory. Various builds and packaging will be possible in the lower hierarchy.
$ pwd
/path/to/SlackBotService
$ qibuild init
$ qipy bootstrap
$ pip install slackbot
The required modules will be installed together. Copy the following installed modules under SlackBotService / lib.
$ pwd
/path/to/SlackBotService/lib
$ ls
backports/
slackbot/
slacker/
websocket/
six.py
Copy websocket / cacert.pem under SlackBotService / lib.
$ pwd
/path/to/SlackBotService/lib
$ ls
backports/
slackbot/
slacker/
websocket/
six.py
cacert.pem
Describe the settings of SlackBot.
SlackBotService/bot_settings.py
# -*- coding: utf-8 -*-
import os
from slackbot import settings
settings.API_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
settings.DEFAULT_REPLY = u"It is not well understood."
settings.PLUGINS = [
'plugins',
]
os.environ['WEBSOCKET_CLIENT_CA_BUNDLE'] = os.path.join('./bin', 'cacert.pem')
The following part loads the above key file which is not bundled at the time of packaging. Of course, I get a warning, but I didn't want to pollute the environment of Pepper itself, so I did this once.
os.environ['WEBSOCKET_CLIENT_CA_BUNDLE'] = os.path.join('./bin', 'cacert.pem')
Run SlackBot when running the script.
SlackBotService/slackbotservice.py
# -*- coding: utf-8 -*-
from slackbot.bot import Bot
from bot_settings import *
class SlackBotService:
def __init__(self):
self.bot = Bot()
self.bot.run()
def main():
slackbotservice = SlackBotService()
if __name__ == "__main__":
main()
If something is spoken, try to make Pepper speak.
SlackBotService/lib/plugins/mention.py
# -*- coding: utf-8 -*-
from slackbot.bot import respond_to, listen_to
from slacker import Slacker
from plugins import proxy
from bot_settings import settings
slack = Slacker(settings.API_TOKEN)
@respond_to(u'')
def respond_any_word(message):
"""
Receive any character.
:param message:Received message object
"""
_text = message.body.get('text', '')
_ts = message.body.get('ts', '')
_user = message.body.get('user', '')
_team = message.body.get('team', '')
_type = message.body.get('type', '')
_channel = message.body.get('channel', '')
proxy.animated_speech(_text)
message.reply("done")
SlackBotService/lib/plugins/proxy.py
# -*- coding: utf-8 -*-
from naoqi import ALProxy
animatedSpeechProxy = ALProxy("ALAnimatedSpeech", "127.0.0.1", 9559)
def animated_speech(text):
_text = text if isinstance(text, str) else text.encode("utf-8")
configuration = {"bodyLanguageMode": "contextual"}
animatedSpeechProxy.say(_text, configuration)
qiproject.xml Define the module to bundle. All necessary modules such as libraries and scripts are defined.
<project version="3">
<qipython name="slackbotservice">
<package name="backports" src="lib" />
<package name="slackbot" src="lib" />
<package name="slacker" src="lib" />
<package name="websocket" src="lib" />
<package name="plugins" src="lib" />
<script src="lib/six.py" />
<script src="lib/cacert.pem" />
<script src="slackbotservice.py" />
<script src="bot_settings.py" />
</qipython>
</project>
manifest.xml
Define the service.
The \
<package uuid="slackbotservice" version="0.1.0">
<services>
<service name="SlackBotService" autorun="true"
execStart="/bin/bash ./python bin/slackbotservice.py" />
<executableFiles>
<file path="python" />
</executableFiles>
</services>
<requirements>
<naoqiRequirement minVersion="2.3"/>
<robotRequirement model="JULIETTE"/>
</requirements>
</package>
Define the package.
<?xml version="1.0" encoding="UTF-8" ?>
<Package name="slackbotservice" format_version="4">
<Manifest src="manifest.xml" />
<qipython name="slackbotservice" />
</Package>
$ qipy install slackbotservice
$ qipkg make-package slackbotservice.pml
$ qipkg deploy-package slackbotservice-0.1.0.pkg --url nao@<Pepper IP>
You can now have Pepper speak via Slack!
It was very convenient because it became possible to call various AL modules via Slack. At the moment, it is not registered as a service, so you cannot operate SlackBot from various work apps. By registering as a service, you will be able to start and stop SlackBot itself, exchange messages with work apps, and so on.
I think that if you use SlackBot well, you can use it for cooperation between work apps and communication between Pepper.
Recommended Posts