Class: Dingtalk::Robot

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/dingtalk/robot.rb,
lib/dingtalk/robot/errors.rb,
lib/dingtalk/robot/version.rb,
lib/dingtalk/robot/configurable.rb,
lib/dingtalk/robot/strategies/text_strategy.rb,
lib/dingtalk/robot/strategies/markdown_strategy.rb

Overview

DingTalk Group Robot

Defined Under Namespace

Modules: Configurable Classes: ConfigurationError, Error, MarkdownStrategy, TextStrategy

Constant Summary collapse

VERSION =
'0.2.0'
VALID_MESSAGE_TYPES =
Dir["#{__dir__}/strategies/*"].map { |path| File.basename(path, '_strategy.rb').to_sym }
WEBHOOK_BASE_URL =
'https://oapi.dingtalk.com/robot/send?access_token='

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initialize(channel, message_type = nil, &context_block) ⇒ Robot

Returns a new instance of Robot.

Examples:

# Config api token and message template directory
Dingtalk::Robot.config.tokens       = { order: 'WEBHOOK...' }
Dingtalk::Robot.config.template_dir = '.'
system %q(echo 'hello, <%= @name %>' > order.text.erb)

# Notify message
robot = Dingtalk::Robot.new(:order) { @name = 'Pine Wong' }
robot.notify

Parameters:

  • channel (#to_sym)

    Set both api token and message template

  • message_type (#to_sym) (defaults to: nil)

    (:text) Message type


28
29
30
31
32
# File 'lib/dingtalk/robot.rb', line 28

def initialize(channel, message_type = nil, &context_block)
  @channel = channel.to_sym
  self.message_type = message_type&.to_sym
  @context_block = context_block
end