Class: Leash::Integration::SlackClient

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/integration/slack.rb

Instance Method Summary collapse

Constructor Details

#initialize(leash) ⇒ SlackClient

Create a new Slack integration client.

Parameters:

  • leash (Leash::Client)

    the Leash SDK client



11
12
13
# File 'lib/leash/integration/slack.rb', line 11

def initialize(leash)
  @leash = leash
end

Instance Method Details

#slack_add_reaction(channel_id, timestamp, reaction) ⇒ Object

Add a reaction emoji to a message

Parameters:

  • channel_id (String)

    The ID of the channel containing the message

  • timestamp (String)

    The timestamp of the message to react to

  • reaction (String)

    The name of the emoji reaction (without ::)

Returns:

  • (Object)


62
63
64
65
66
67
68
69
# File 'lib/leash/integration/slack.rb', line 62

def slack_add_reaction(channel_id, timestamp, reaction)
  params = {
    'channel_id' => channel_id,
    'timestamp' => timestamp,
    'reaction' => reaction
  }.compact
  @leash.call('slack', 'slack_add_reaction', params)
end

#slack_get_channel_history(channel_id, limit: nil) ⇒ Object

Get recent messages from a channel

Parameters:

  • channel_id (String)

    The ID of the channel

  • limit (Float, nil) (defaults to: nil)

    Number of messages to retrieve (default 10)

Returns:

  • (Object)


76
77
78
79
80
81
82
# File 'lib/leash/integration/slack.rb', line 76

def slack_get_channel_history(channel_id, limit: nil)
  params = {
    'channel_id' => channel_id,
    'limit' => limit
  }.compact
  @leash.call('slack', 'slack_get_channel_history', params)
end

#slack_get_thread_replies(channel_id, thread_ts) ⇒ Object

Get all replies in a message thread

Parameters:

  • channel_id (String)

    The ID of the channel containing the thread

  • thread_ts (String)

    The timestamp of the parent message in the format ‘1234567890.123456’. Timestamps in the format without the period can be converted by adding the period such that 6 numbers come after it.

Returns:

  • (Object)


89
90
91
92
93
94
95
# File 'lib/leash/integration/slack.rb', line 89

def slack_get_thread_replies(channel_id, thread_ts)
  params = {
    'channel_id' => channel_id,
    'thread_ts' => thread_ts
  }.compact
  @leash.call('slack', 'slack_get_thread_replies', params)
end

#slack_get_user_profile(user_id) ⇒ Object

Get detailed profile information for a specific user

Parameters:

  • user_id (String)

    The ID of the user

Returns:

  • (Object)


114
115
116
117
118
119
# File 'lib/leash/integration/slack.rb', line 114

def (user_id)
  params = {
    'user_id' => user_id
  }.compact
  @leash.call('slack', 'slack_get_user_profile', params)
end

#slack_get_users(cursor: nil, limit: nil) ⇒ Object

Get a list of all users in the workspace with their basic profile information

Parameters:

  • cursor (String, nil) (defaults to: nil)

    Pagination cursor for next page of results

  • limit (Float, nil) (defaults to: nil)

    Maximum number of users to return (default 100, max 200)

Returns:

  • (Object)


102
103
104
105
106
107
108
# File 'lib/leash/integration/slack.rb', line 102

def slack_get_users(cursor: nil, limit: nil)
  params = {
    'cursor' => cursor,
    'limit' => limit
  }.compact
  @leash.call('slack', 'slack_get_users', params)
end

#slack_list_channels(limit: nil, cursor: nil) ⇒ Object

List public or pre-defined channels in the workspace with pagination

Parameters:

  • limit (Float, nil) (defaults to: nil)

    Maximum number of channels to return (default 100, max 200)

  • cursor (String, nil) (defaults to: nil)

    Pagination cursor for next page of results

Returns:

  • (Object)


20
21
22
23
24
25
26
# File 'lib/leash/integration/slack.rb', line 20

def slack_list_channels(limit: nil, cursor: nil)
  params = {
    'limit' => limit,
    'cursor' => cursor
  }.compact
  @leash.call('slack', 'slack_list_channels', params)
end

#slack_post_message(channel_id, text) ⇒ Object

Post a new message to a Slack channel

Parameters:

  • channel_id (String)

    The ID of the channel to post to

  • text (String)

    The message text to post

Returns:

  • (Object)


33
34
35
36
37
38
39
# File 'lib/leash/integration/slack.rb', line 33

def slack_post_message(channel_id, text)
  params = {
    'channel_id' => channel_id,
    'text' => text
  }.compact
  @leash.call('slack', 'slack_post_message', params)
end

#slack_reply_to_thread(channel_id, thread_ts, text) ⇒ Object

Reply to a specific message thread in Slack

Parameters:

  • channel_id (String)

    The ID of the channel containing the thread

  • thread_ts (String)

    The timestamp of the parent message in the format ‘1234567890.123456’. Timestamps in the format without the period can be converted by adding the period such that 6 numbers come after it.

  • text (String)

    The reply text

Returns:

  • (Object)


47
48
49
50
51
52
53
54
# File 'lib/leash/integration/slack.rb', line 47

def slack_reply_to_thread(channel_id, thread_ts, text)
  params = {
    'channel_id' => channel_id,
    'thread_ts' => thread_ts,
    'text' => text
  }.compact
  @leash.call('slack', 'slack_reply_to_thread', params)
end