Skip to content

Instantly share code, notes, and snippets.

@sat0ken
Created December 4, 2017 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sat0ken/69e875ce8b9aeb1145865e13d79421a1 to your computer and use it in GitHub Desktop.
Save sat0ken/69e875ce8b9aeb1145865e13d79421a1 to your computer and use it in GitHub Desktop.
import socket
import ssl
def send_message():
s = socket.socket()
ai = socket.getaddrinfo("slack.com", 443)
print("Address infos:", ai)
addr = ai[0][-1]
s.connect(addr)
s = ssl.wrap_socket(s)
send_data = "token=yourtoken&channel=%23yourchannel&text=Hello!! Meassage from Micropython&username=yourname"
s.write(b"POST /api/chat.postMessage HTTP/1.1\r\n")
s.write(b"Host: slack.com\r\n")
s.write(b"Accept: */*\r\n")
s.write(b"Content-Length: %d\r\n" % len(send_data))
s.write(b"Content-Type: application/x-www-form-urlencoded\r\n")
s.write(b"Connection: close\r\n")
s.write(b"\r\n")
s.write(send_data)
print(s.read(4096))
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment