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

How to refer to user with @ notation #172

Open
shubhamitc opened this issue Apr 25, 2016 · 2 comments
Open

How to refer to user with @ notation #172

shubhamitc opened this issue Apr 25, 2016 · 2 comments

Comments

@shubhamitc
Copy link

I want to configure Hipchat to support Hubot a robot system works for collaborator tools. In order for that to work messages sent by backend monitoring system should address to user Hubot.

With this api i am not able to send message to user. using '@' does not work with send_msg api.

@shubhamitc
Copy link
Author

My Code,

#!/usr/bin/env ruby

require 'hipchat'
require 'trollop'
module HipChat`
  class NotifyRoomCli 
    def initialize(api_token, room_name, msg, options={})
      defaults = { hipchat_options: {api_version: 'v2',server_url: 'https://api.hipchat.com'}, msg_options: {:notify => true}, excluded_envs: [], msg_prefix: ''}
      options = defaults.merge(options)
      @api_token = api_token
      @room_name = room_name
      @msg = msg
      @hipchat_options = options[:hipchat_options]
      @msg_options = options[:msg_options]
      @msg_prefix = options[:msg_prefix]
      @excluded_envs = options[:excluded_envs]
      @to_user=options[:name]
      case 
      when options[:alerttype].match(/warning/i)
        @color = 'yellow'
      when options[:alerttype].match(/critical/i)
        @color = 'red'
      when options[:alerttype].match(/info/i)
        @color = 'green'
      end if options[:alerttype]
    end

    def report
      if @msg
        @msg_options[:color]=(@color || 'yellow')
        client = HipChat::Client.new(@api_token, @hipchat_options)
        client[@room_name].send(@to_user, [@msg_prefix, @msg].join(' '), @msg_options)
      end
    end
  end
end
begin
  opts = Trollop::options do
    opt :message, "Use monkey mode"  ,:type => :string                  # flag --monkey, default false
    opt :name, "Monkey name", :type => :string        # string --name <s>, default nil
    opt :apitoken, "HIPCHAT API Token 2.0", :type=> :string
    opt :roomname, "Room id from Hipchat", :type=> :string
    opt :alerttype, "warning/critical/info", :type => :string
  end
  [ :message, :apitoken, :roomname].each do |key|
    Trollop::die "arguments required --#{key}" unless opts[key]
  end
  hipchat=HipChat::NotifyRoomCli.new(opts[:apitoken],opts[:roomname],opts[:message],opts)
  hipchat.report
rescue Errno::ENOENT => err
  abort "hip_chat_cli: #{err.message}"
end`

@hirogen317
Copy link

shubhamitcさん、
Please try to set message_format:

client['hokehoke'].send('hokehoke', '@all, hello world', :message_format => 'text')
Reference:
https://developer.atlassian.com/hipchat/guide/sending-messages

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

2 participants