Skip to content

Instantly share code, notes, and snippets.

@kassi
Last active June 21, 2021 11:35
Show Gist options
  • Save kassi/05d9ce764157bf91aba4949067e20131 to your computer and use it in GitHub Desktop.
Save kassi/05d9ce764157bf91aba4949067e20131 to your computer and use it in GitHub Desktop.
Reflect your zoom status in slack.

Simple hammerspoon service to set slack status when you're in a zoom call and back.

  1. Create or install a slack app that provides an API token (e.g. "API Token")
  2. Write the token to ~/.config/slack/token
  3. Install hammerspoon (https://www.hammerspoon.org/, brew install hammerspoon) and the the files below into ~/.hammerspoon or merge them (init.lua)
  4. If your language is "zh", check the local in zoom.lua.
require("zoom")
require("hs.http")
local open = io.open
local function read_file(path)
local file = open(path, "rb")
if not file then return nil end
local content = file:read "*a"
file:close()
return content
end
local token=nil
function readToken()
if token == nil then
local tokenFile = os.getenv("HOME") .. "/.config/slack/token"
token=string.gsub(read_file(tokenFile), "\n$", "")
end
end
function slackApi(method, path, data)
readToken()
code, body, headers = hs.http.doRequest(
"https://slack.com/api/" .. path,
method,
data,
{
Authorization = "Bearer " .. token
}
)
end
function setSlackStatus(emoji, text)
slackApi(
"POST",
"users.profile.set",
"profile={\"status_emoji\":\"" .. emoji .. "\",\"status_text\":\"" .. text .. "\"}"
)
end
function clearSlackStatus()
slackApi(
"POST",
"users.profile.set",
"profile={\"status_emoji\":\"\",\"status_text\":\"\"}"
)
end
require("slack")
check_interval=10 -- number of seconds to check zomo status
notify_status_change = false -- whether you also want a desktop notification
locale_menu = {
de = "Dem Meeting beitreten...",
en = "Join Meeting...",
es = "Entrar a la Reunión...",
fr = "Rejoindre la réunion",
it = "Entra nella riunione...",
ja = "ミーティングに参加...",
ko = "회의 참가...",
pt = "Ingressar na Reunião...",
ru = "Войти в конференцию...",
vi = "Tham gia cuộc họp...",
zh = "加入会议...",
-- zh = "加入會議中...",
}
language = string.sub(hs.host.locale.preferredLanguages()[1],1,2)
function update_status(status)
if status == "zoom" then
setSlackStatus(":zoom:", "On a call")
else
clearSlackStatus()
end
end
function in_zoom_meeting()
local app = hs.application.find("zoom.us")
if app ~= nil then
local menu_item = app:findMenuItem(locale_menu[language])
return menu_item ~= nil and not menu_item["enabled"]
else
return false
end
end
zoom_meeting_running = false
zoom_timer = hs.timer.doEvery(check_interval, function()
if in_zoom_meeting() then
if zoom_meeting_running == false then
zoom_meeting_running = true
update_status("zoom")
if notify_status_change then
hs.notify.show("Started zoom meeting", "Updating slack status", "")
end
end
else
if zoom_meeting_running == true then
zoom_meeting_running = false
update_status("none")
if notify_status_change then
hs.notify.show("Left zoom meeting", "Updating slack status", "")
end
end
end
end)
zoom_timer:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment