Skip to content

arith-alexander/GithubChatworkBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GithubChatworkBot

Send github event messages to specified Chatwork room with corresponding "To:" field. See code commentaries for more details.

General information

Before using class you must get Chatwork API Key, add bot account to all designated Chatwork rooms and configure Github webhooks. Webhook config (go to Github repository configuration page and open "Webhooks & Services" tab):

  • Payload url - set to url, where GithubChatworkBot.execute() method is called;
  • Content type - application/x-www-form-urlencoded
  • Select individual events - Commit comment, Issues, Pull Request, Issue comment, Pull Request review comment

To start cgi http server execute this in server home folder (i.e. folder, that contains "cgi-bin" folder):

python3 -m http.server --cgi

To start server on reboot copy pyserv to /etc/init.d, change path to scripts inside it and launch

chkconfig --add pyserv

For testing environment you can use ngrok to make server available from internet:

./ngrok http 80

Rename cgi-bin/config.py.sample to cgi-bin/config.py and set required configuration. Rename logs/log.txt.sample to logs/log.txt and add write rights.

Class usage

Creating instance:

botInstance = GithubChatworkBot()

Setting payload:

botInstance.setPayload(cgi.FieldStorage())

Setting chatwork room id, where messages goes, and corresponding repository names. Example below means, that events from repository somerepo goes to chatwork room 36410221 and 34543645, also events from moreonerepo goes to room 34543645. Do not forget to add bot to all rooms and configure webhooks on all repositories!!

botInstance.repository_room_map = {"somerepo": ["36410221", "34543645"], "moreonerepo": ["34543645"]}

Setting chatwork API token

botInstance.chatwork_token = "4033...12c7"

Switch logging ON (better to switch OFF for production):

botInstance.logging = True

Setting chatwork message max length to prevent flooding

botInstance.chatwork_message_max_len = 200

Setting account map in format {"github user account id": "chatwork user account name"} Example below means, that Github user arith_tanaka has Chatwork account id 123456

botInstance.chatwork_github_account_map = {"123456": "arith_tanaka", "567890": "arith_yamada"}

Execute POST to Chatwork:

botInstance.execute()

About

Send github event messages to specified Chatwork room with corresponding "To:" field.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •