Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slackchannel? What is it job? #31

Closed
timetoexpire opened this issue Jan 6, 2022 · 3 comments
Closed

slackchannel? What is it job? #31

timetoexpire opened this issue Jan 6, 2022 · 3 comments

Comments

@timetoexpire
Copy link

Been lookin in to slack. And must be doing something wrong or something but I don't see point in script variable slackchannel.
slackchannel="" # Slack Channel #example
It dosn't seam to do anything. It could be null value, it could have a Slack channel under my account, could be set anything like total random nonsence. Make no diffrance.
You could remove code on line 87 and 97 and still works.
"channel": "'$slackchannel'",

So what is job? Because I would nice if webhooks I have that would be able to post another channel, but it will only post to channel that defiened when creating that webhook.

@K0p1-Git
Copy link
Owner

Hey @northportio, if its possible do take a look at this.

@northportio
Copy link
Contributor

Thanks for queuing me in @K0p1-Git.

I haven't looked into this in-depth yet but I'll explore this more.

My initial answer:

To the best of my knowledge, I may be incorrect here but you basically create the app in slack, copy the webhook to the script and then add the app to the channel (that gives authorization to post in said channel). If you had the app added to multiple channels, I believe that's where the channel name designation matters.

I will look into this more on my spare time but that's my initial answer. Hope that somewhat answers your question.

@Sailboat265
Copy link
Contributor

Sailboat265 commented Jan 19, 2022

@northportio Yep! You're correct however...(Hey! Just my two cents opinion down here)

Afaik, because of security scopes, Webhooks are usually tied to a specific channel. Each webhooks uri is unique, no matter the app, destination channel etc. (You can try create a duplicate webhook, and see that the request uri is different even thought they post to the same channel, from the same app etc)

To implement channel name designation, i think the following steps must be done.

An user needs to go to here. Create an app, and go to OAuth & Permissions, then setup the necessary OAuth permission scopes like channels:read for reading available channels, and chat:write for sending messages.

Then copy the bot user oauth token, it usually starts with xoxb-<...>.

Then post request code shall be like:

#!/bin/bash
slack_api_url="https://slack.com/api/chat.postMessage"
slack_app_token="your-bot-user-oauth-token-here"
slack_channel="general"

slack=$(curl -s -X POST $slack_api_url \
    -H "Authorization: Bearer $slack_app_token" \
    -H "Content-type: application/json; charset=UTF-8" \
    --data "{\"channel\":\"$slack_channel\",\"text\": \"Hello world! I'm sending message to $slack_channel channel.\"}")

If you're interested, you can learn more here!

  1. Message Posting API
  2. Webhooks

@K0p1-Git K0p1-Git closed this as completed May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants