설치
Make sure to Download "Binary"
실행
zookeeper & kafka 서버 실행
WIN10@DESKTOP:~$ zookeeper-server-start config/zookeeper.properties
WIN10@DESKTOP:~$ kafka-server-start config/server.properties
Kafka 설치
WIN10@DESKTOP:~$ pip install confluent-kafka
Slack API with Ajou University notices parser
First, invite your bot to your channel. (In this example, we set it as "#아주대")
The producer will notify the consumer whenever there are new notices.
The producer checks new notices per an hour, saves latest 10 notices to json file, and sees if there is/are a new notice/s.
If there is a new notice, it sends {"TITLE": "title", "DATE": "post date", "LINK": "http address", "WRITER": "writer"} to the consumer.
The consumer checks new datas every 5 seconds, if it gets a new data, it consumes the data and leave a comment like this below image.
🅱️ Run the server first to see the results.
WIN10@DESKTOP:~$ python AjouSlackProducer.py
WIN10@DESKTOP:~$ python AjouSlackConsumer.py
Slack API Producer Usage
Invite your bot to user community channel and your developer channel.
This producer sends a data if users post comments containing a word, "bug".
example data)
{ "USER": "ikr", "TEXT": "I found a bug! I can keep copying my items to my inventory." }
Then the consumer below, will consume the data and posts a message in your developer channel.
"USERNAME: MESSAGE: Please see if we can fix it right here, right now"
Slack API Consumer Usage
Modified version of official Confluent example
Add "chat:write" scope to both user and bot.
Copy Bot User OAuth Access Token from OAuth & Permissions section.
/INVITE @BOTNAME
to your channel if you see an error, "** FAILED: not_in_channel"
Using CLI or producers, send a data to your kafka topic.
kafka-console-producer --broker-list localhost:9092 --topic SLACK-KAFKA
> {"CLUB_STATUS":"platinum","EMAIL":"ikr@kakao.com","STARS":1,"MESSAGE":"Exceeded all my expectations!"}
Whenever you send a data to kafka, this consumer consumes email and message from the user, and posts "EMAIL just left a bad review" to your slack channel.
Result
Sending message "`ikr@kakao.com` just left a bad review :disappointed:
> Exceeded all my expectations!
_Please contact them immediately and see if we can fix the issue *right here, right now*_" to channel kafka