5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Subscriber経由でSlackに投稿する

Posted at

ROSのSubscriber経由でSlackに投稿してみた。例によって需要は考えていない。

SlackClientを使うと簡単にSlackとつなげれる。

準備

pip install slackclient

pipでSlackのWeb APIのライブラリを入れておく。(ROSって仮想環境どうしたらいいだろ?)

コード

SubscriberのコールバックでSlackに投稿している。チャンネルとかユーザー名はパラメータ化してもよいかも。

sc.py
# !/usr/bin/env python

import rospy

from std_msgs.msg import String
from slackclient import SlackClient

token = "TOKEN" # トークンは https://api.slack.com/web で作る
username = "ros"
channel = "#ros"

sc = SlackClient(token)

def callback(message):
    print sc.api_call("chat.postMessage", channel=channel, text=message.data, username=username)

rospy.init_node("rosslack")
sub = rospy.Subscriber("postMessage", String, callback)
rospy.spin()

実行

chmod +x sc.py
./sc.py

別コンソールから rostopic を使ってPublishをする。

rostopic pub /postMessage std_msgs/String -- 'hoge'

これで、Slackの画面を見てみるとROSからメッセージが届いているはず。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?