Last active
October 18, 2015 00:48
-
-
Save ykyk1218/b959026926a7dc6005d9 to your computer and use it in GitHub Desktop.
Hubot+TwitterStreaming APIでUser streamsを監視して、指定したキーワードがあったら自動でtwitterのお気に入りに登録する ref: http://qiita.com/ykyk1218/items/7bf8f7280ca7d1cabd65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ heroku config:set HUBOT_TWITTER_KEY="value" | |
$ heroku config:set HUBOT_TWITTER_SECRET="value" | |
$ heroku config:set HUBOT_TWITTER_TOKEN="value" | |
$ heroku config:set HUBOT_TWITTER_TOKEN_SECRET="value" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export HUBOT_TWITTER_KEY="consumer key" | |
export HUBOT_TWITTER_SECRET="consumer secret" | |
export HUBOT_TWITTER_TOKEN="token" | |
export HUBOT_TWITTER_TOKEN_SECRET="token secret" | |
bin/hubot -a twitter-ext -n TwitterMonitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (robot) -> | |
robot.hear /プログラマー|エンジニア/, (res) -> | |
# お気に入りに登録する | |
fav_api_url = "https://api.twitter.com/1.1/favorites/create.json" | |
tweet_id = res.message.user.status_id | |
twitter = require('twitter') | |
client = new twitter( | |
consumer_key : process.env.HUBOT_TWITTER_KEY | |
consumer_secret : process.env.HUBOT_TWITTER_SECRET | |
access_token_key : process.env.HUBOT_TWITTER_TOKEN | |
access_token_secret: process.env.HUBOT_TWITTER_TOKEN_SECRET | |
) | |
client.post fav_api_url, {id: tweet_id}, (data, err) -> | |
if err | |
console.log err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot = new TwitterStreaming(options) | |
(省略) | |
bot.timeline "", (data, err) -> | |
self.x +=1 | |
console.log "received #{data.text} from #{data.user.screen_name}" | |
tmsg = new TextMessage({user: data.user.screen_name, status_id: data.id_str}, data.text) | |
self.receive tmsg | |
if err | |
console.log err | |
class TwitterStreaming extends EventEmitter | |
constructor: (options) -> | |
if options.token? and options.secret? and options.key? and options.tokensecret? | |
@token = options.token | |
@secret = options.secret | |
@key = options.key | |
@domain = 'stream.twitter.com' | |
@userdomain = 'userstream.twitter.com' | |
@tokensecret = options.tokensecret | |
@consumer = new oauth.OAuth "https://twitter.com/oauth/request_token", | |
"https://twitter.com/oauth/access_token", | |
@key, | |
@secret, | |
"1.0A", | |
"", | |
"HMAC-SHA1" | |
else | |
throw new Error("Not enough parameters provided. I need a key, a secret, a token, a secret token") | |
(省略) | |
timeline: (track, callback) -> | |
@post @userdomain, "/1.1/user.json?track=#{track}", '', callback | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment