{"id":16971599,"url":"https://github.com/thomastjdev/nim_slacklib","last_synced_at":"2025-07-14T06:04:25.296Z","repository":{"id":87657525,"uuid":"99314497","full_name":"ThomasTJdev/nim_slacklib","owner":"ThomasTJdev","description":"Nim-lang library for working with a slack app or sending messages to a slack channel","archived":false,"fork":false,"pushed_at":"2017-08-07T10:06:05.000Z","size":24,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T12:53:08.370Z","etag":null,"topics":["library","nim-lang","slack","slack-api","slack-app","slack-commands","slack-webhook"],"latest_commit_sha":null,"homepage":null,"language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThomasTJdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-04T07:09:25.000Z","updated_at":"2023-03-17T05:19:14.000Z","dependencies_parsed_at":"2023-03-13T18:40:18.523Z","dependency_job_id":null,"html_url":"https://github.com/ThomasTJdev/nim_slacklib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ThomasTJdev/nim_slacklib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasTJdev%2Fnim_slacklib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasTJdev%2Fnim_slacklib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasTJdev%2Fnim_slacklib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasTJdev%2Fnim_slacklib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThomasTJdev","download_url":"https://codeload.github.com/ThomasTJdev/nim_slacklib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasTJdev%2Fnim_slacklib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265249361,"owners_count":23734439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","nim-lang","slack","slack-api","slack-app","slack-commands","slack-webhook"],"created_at":"2024-10-14T00:52:52.625Z","updated_at":"2025-07-14T06:04:24.577Z","avatar_url":"https://github.com/ThomasTJdev.png","language":"Nim","readme":"\n\n\n# slacklib\n\nNim-lang library for working with a slack app or sending messages to a slack channel\n\n# General\n\nThis nim file was created with the purpose to control a Raspberry Pi 3.\n\nThe lib has 3 main purposes:\n\n1. Responding to the `slack app verification` with the \"challenge\". This will verify you connection and is required by slack.\n2. Accessing commands sent in the slack chat, parsing them and responding\n3. Send messages using the incoming webhook app\n\n# Prerequisites\n\n## Slack account\nGet a slack account (https://slack.com)\n\n## Slack app\nYou need to build a slack app to communicate with.\n\n1) Create a new slack app (https://api.slack.com/apps/new)\n2) Add the permissions depending on your needs: Incoming webhooks, Slash commands, Permissions\n3) Install the app to your team\n4) Scopes: commands, incoming webhooks\n\n## Router\n\nYou need to open the slackPort in your router to communicate with slack.\n\n## Include slacklib in your code\n\n### Imports\n\n```nim\nimport asyncdispatch, asynchttpserver, slacklib\n```\n\n### Adjust slack port (optional)\n\nChange the port (optional). Otherwise port 33556 is used.\n\n```nim\nslackPort = Port(65432)\n```\n\n### Add to your code\n\n#### Proc\n\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n```\n\n#### Runner\n\nChoose the prefeered option below: \n\n```nim\nwaitFor slackServer.serve(slackPort, slackServerRun)\n```\n\n\n\n```nim\nasyncCheck slackServer.serve(slackPort, slackServerRun)\nrunForever()\n```\n\n\n## Compiler\n\nWhen compiling and using the webhook, you need to include `-d:ssl` since the communication with slack is using HTTPS:\n\n`nim c -d:ssl main.nim`\n\n\n# Examples\n\nAll the examples using slackServerRun* requires you to activate it with either waitFor or asyncCheck.\n\nPlease be aware, that when sending commands from you channel, the channel awaits a response. You always need to respond to a command.\n\n## Change port\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Standard port is been used. To change it:\n  slackPort = Port(3000)\n```\n\n## Verify your app connection\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Verify you app connection. This is a one-timer, only use it for verifing connection to your app\n  slackVerifyConnection(slackReq) \n```\n\n## Access the request as string\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Access the event as a string\n  echo slackEventString(slackReq)\n```\n\n## Access the request as a JsonNode\n```nim\nimport json\n\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Access the event as a JsonNode\n  echo slackEventJson(slackReq)\n  echo slackEventJson(slackReq)[\"command\"].getStr\n```\n\n## Access the request as a Json value\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Access a value from the event as a string\n  echo slackEvent(slackReq, \"command\")\n```\n\n## Access the request as a Request\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Access the event as a Request\n  #[\n    Request = object\n      client*: AsyncSocket\n      reqMethod*: HttpMethod\n      headers*: HttpHeaders\n      protocol*: tuple[orig: string, major, minor: int]\n      url*: Uri\n      hostname*: string\n      body*: string\n  ]#\n  echo $slackReq.body\n```\n\n\n## Case the command and respond appropriate\n```nim\nproc slackServerRun*(slackReq: asynchttpserver.Request) {.async.} =\n  # Case the command\n  # slackEvent always return a string, use slackEventJson(slackReq)[\"someField\"].xxx to access in other types\n\n  case slackEvent(slackReq, \"command\"):\n  of \"/arm\": \n    # If you need to run a proc with the arguments sent, access the 'text' field:\n    echo slackEvent(slackReq, \"text\")\n    await slackRespond(slackReq, slackMsg(\"#general\", \"nimslack\", \"ARMED\", \"\", \"warning\", \"Alarm Update\", \"The alarm has been armed\"))\n\n  of \"/disarm\":\n    echo \"DISARMED\"\n    await slackRespond(slackReq, slackMsg(\"#general\", \"nimslack\", \"DISARMED\", \"\", \"good\", \"Alarm Update\", \"The alarm has been disarmed\"))\n\n  else:\n    await slackRespond(slackReq, slackMsg(\"#general\", \"nimslack\", \"ERROR\", \"\", \"danget\", \"Alarm Update\", \"That command is not part of me\"))   \n```\n\n\n## Send a message using the webhook (async)\n\nJust sending a command using the webhook, can be performed anywhere in your code\n\n```nim\n# A message can be sent from anywhere in you code, with this command\n# It is a requirement, that you have defined the the var 'slackIncomingWebhookUrl' first\nasyncCheck slackSend(slackMsg(\"#general\", \"nimslack\", \"Hi dude\", \"\", \"good\", \"Sup?\", \"Just sending a message\"))\n```\n\n## Send a message using the webhook (sync)\n\nJust sending a command using the webhook, can be performed anywhere in your code.\n\nThis method does not utilize the async - it is synchronous.\n\nIt returns the Reponse.body as a string.\n\n```nim\n# A message can be sent from anywhere in you code, with this command\n# It is a requirement, that you have defined the the var 'slackIncomingWebhookUrl' first\nlet msgResponse = slackSendSyn(slackMsg(\"#general\", \"nimslack\", \"Hi dude\", \"\", \"good\", \"Sup?\", \"Just sending a message\"))\necho msgResponse\n```\n\n## Prepare constants with predefined messages\n```nim\n# Already know you messages? Prepare them as constants (in the top):\nconst msgOn = slackMsg(\"nimslack\", \"Alarms is turned on\", \"good\", \"Alarm Update\", \"The controller has been turned on\")\n\n# A message can be sent from anywhere in you code, with this command\n# It is a requirement, that you have defined the the var 'incomingWebhookUrl' first\nasyncCheck slackSend(msgOn)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomastjdev%2Fnim_slacklib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomastjdev%2Fnim_slacklib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomastjdev%2Fnim_slacklib/lists"}