Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9acd8b1

Browse files
Added slack_bot
1 parent ce8fa75 commit 9acd8b1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎slack-bot/bot_slack.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os, time, re
2+
from parseconfig import read_config
3+
from slackclient import SlackClient
4+
5+
CONFIG_FILE = 'slack.ini'
6+
slack_token = read_config(CONFIG_FILE)
7+
print(type(slack_token))
8+
9+
sc = SlackClient(slack_token)
10+
print(sc)
11+
12+
def send_slack_msg(channel = "general", msg = "empty message", attachments = []):
13+
return sc.api_call(
14+
"chat.postMessage",
15+
channel = channel,
16+
text = msg,
17+
attachments = [attachments]
18+
)
19+
'''
20+
"chat.postMessage",
21+
channel = "general",
22+
text = "Hello from Python! :tada:",
23+
attachments = [{
24+
"fallback": "Required plain-text summary of the attachment.",
25+
"color": "#2eb886",
26+
"pretext": "Optional text that appears above the attachment block",
27+
"author_name": "Bobby Tables",
28+
"author_link": "http://flickr.com/bobby/",
29+
"author_icon": "http://flickr.com/icons/bobby.jpg",
30+
"title": "Slack API Documentation",
31+
"title_link": "https://api.slack.com/",
32+
"text": "Optional text that appears within the attachment",
33+
"fields": [{
34+
"title": "Priority",
35+
"value": "High",
36+
"short": False
37+
}],
38+
"footer": "Slack API",
39+
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
40+
"ts": 123456789
41+
'''
42+
43+
def main():
44+
channel = "random"
45+
msg = "Hello world"
46+
attachments = { "text" : "My attachments" }
47+
response = send_slack_msg(channel, msg, attachments)
48+
if response["ok"]:
49+
print("Posted successfully.!")
50+
else:
51+
print(response)
52+
53+
if __name__ == '__main__':
54+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /