Code Monkey home page Code Monkey logo

Comments (4)

dblock avatar dblock commented on June 21, 2024

This is really a Slack API question, but looking at chat_postMessage it looks like this is controlled by the value of broadcast? Try setting it to false?

https://api.slack.com/methods/chat.postMessage#arg_reply_broadcast

from slack-ruby-bot.

ReshmaUmapathy avatar ReshmaUmapathy commented on June 21, 2024

Hi,
NO, not using chat_postMessage... using client.say method to post it in slack channel.
Issue is not happening when message is sent to slack channel from my app... facing this issue only when a user post a command in slack channel... immediately it is posted as direct message in the channel...

My code:

require "uri"
require "net/http"
module SlackMathbot
  module Commands
    class Calculate < SlackRubyBot::Commands::Base
      command 'Create ticket' do |client, data, _match|
      	url = URI("https://slack.com/api/conversations.history?channel=#{data.channel}&latest=#{data.thread_ts}&inclusive=true&limit=1")
        https = Net::HTTP.new(url.host, url.port);
        https.use_ssl = true
        request = Net::HTTP::Get.new(url)
        request["Authorization"] = ""
        response1 = https.request(request)
        resp1 = response1.read_body
        puts resp1
        ui_name = resp1.split("Transcation Name")[1].split("\\n")[0].split(" ")[2]
        error_class = resp1.split("Error class")[1].split("\\n")[0].split(" ")[2]
        error_path = (resp1.split("Path")[1].split("\\n")[0].split(" ")[2]).delete('\\')
        title = "#{ui_name} #{error_class} - #{error_path}"

        url = URI("https://freshworks.freshrelease.com")
        https = Net::HTTP.new(url.host, url.port);
        https.use_ssl = true
        request = Net::HTTP::Post.new(url)
        request["Authorization"] = "Token token="
        request["Content-Type"] = "application/json"
        request.body = "{\"title\":\"#{title}\",\"issue_type_id\":,\"project_id\":12111,\"tags\": [\"test\"]}"
        response = https.request(request)
        resp = response.read_body
        # get_key(resp,data)
        key = resp.split("key")[1].split(",")[0].split(/\s*-\s*/)[1].split(/\"/)[0]
        fr_url = "https://freshworks.freshrelease.com"
        client.say(channel: data.channel,thread_ts: data.event_ts, text: "Ticket created - #{fr_url}")
      end
    end
  end
end

from slack-ruby-bot.

ReshmaUmapathy avatar ReshmaUmapathy commented on June 21, 2024

This is the response i got when i posted a command in slack channel:
{"ok":true,"channel":"channel_id","ts":"1607755792.000700","message":{"client_msg_id":"client_id","type":"message","text":"<@user_id> create ticket","user":"user_id","ts":"1607755792.000700","team":"team_id","blocks":[{"type":"rich_text","block_id":"tDr","elements":[{"type":"rich_text_section","elements":[{"type":"user","user_id":"user_id"},{"type":"text","text":" create ticket"}]}]}],"thread_ts":"1604574561.000500"}}

Here, thread_ts and ts are different... is it because of that?
If so, how to solve it... where we need to change...

from slack-ruby-bot.

dblock avatar dblock commented on June 21, 2024

This is really a Slack API question, I don't know more than the documentation here. The say implementation is a dumb wrapper.

I would switch to chat_postMessage and call it a day.

Please note that real-time bots are not even accepted in the slack directory any more, you should be using a bot with granular permissions. read this

from slack-ruby-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.