3
votes

I'm working in a slack bot(scope chat:write, commands, and users:read), after initiating the bot, a modal opens up, and on submission, the response should be sent to that bot's DM. I'm using chat.postMessage API to achieve this(something like this https://api.slack.com/tutorials/message-action). Below is the sample code, this works in a workspace from where I created the bot but when I tried the same on a different workspace in getting {"ok"=>false, "error"=>"channel_not_found"}

response = JSON.parse(params[:payload])
user_id = response["user"]["id"]
args = {channel: user_id ,text: "A message"} 
@options = { body: args}
HTTParty.post("https://slack.com/api/chat.postMessage",
  { 
    :body => args.to_json,
    :headers => { 'Content-Type' => 'application/json', 'Authorization' => 'Bearer Bot User OAuth Access Token'}
  })

What the best way to achieve this? I can't submit it to the app directory because the bot needs to be added in at least two workspaces.

1
Plz check whether ur using the right bot token for different workplace.Mothirajha

1 Answers

1
votes

I understood the problem, I'm passing the bot token of a specific workspace to another workspace. The solution is to store the access_token when the user adds the bot to the workspace and send the access_token when posting the message. Thanks for the tip.@mothirajha