手动启动Xcode Bot集成吗? [英] Start Integration of Xcode Bot manually?

查看:123
本文介绍了手动启动Xcode Bot集成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看WWDC 2014与Xcode的持续集成"视频,它看起来很不错,它们可以用来运行测试程序. 但是我的问题是,当他向Jeeves发送消息集成CoffeeBoard"时,看到该视频的任何人.Bot开始集成.我想知道他是怎么做到的.

I was watching WWDC 2014 "Continuous Integration with Xcode" Video and it looks great how the bots can be used to run test. But my question is to anyone who has seen the video, when he sends message to Jeeves saying " integrate CoffeeBoard ".Bot starts to integrate. I want to know how he did that.

我想在github上添加post-receive钩子,该钩子在接收到任何提交后应在我的OS X Server上启动Xcode bot.我的大多数团队成员都使用SourceTree或GitHub来管理他们的git,并且他们不想使用Xcode Source Control.我认为创建一个机器人并将其选项设置为手动启动就可以解决问题.我需要知道,"OS X Server是否为您提供了诸如会启动机器人的url之类的选项?"

I want to add post-receive hook on github which on receiving any commit should start Xcode bot on my OS X Server. Most of my team members use SourceTree or GitHub to manage their git and they don't want to use Xcode Source Control. I thought creating a bot and setting its option to start manually will do the trick. I need to know, "Does OS X Server gives you option like some sort of url which will start a bot? "

对不起,如果我不够清楚.但这对我来说太混乱了,因为他们关于触发器的文档很少.尽管他说这是很酷的新功能,但他们没有提供实现该功能的任何信息

Sorry, If I am not clear enough. But it is too confusing for me as they have very less documentation on triggers. And though he mention it as cool new feature, they have included no information to achieve that

推荐答案

前面的两个答案并不能完全回答最初的问题他们是如何做到的",以便从Messages应用程序中启动机器人.

The prior two answers don't exactly answer the original question of "how they did that" to kick off bots from within Messages app.

我已经重新创建了模仿Jeeves虚拟助手与机器人进行交互(并获取天气)所需的确切工作流程和脚本.

I've recreated the exact workflow and scripts required to mimic the Jeeves virtual assistant for interacting with bots (and for getting the weather).

有关完整的详细信息,请参见链接的PDF文档:

See the linked PDF document for the complete details:

https://s3.amazonaws.com/icefield/IntegratingXcodeBotsWithMessages.pdf

由于我相信通过完整答案的链接引用了该事实,因此删除了原始答案.此编辑将完整的实现详细信息添加为此答案的一部分.我希望很快就可以得到答案.

original answer was deleted due, I believe, to the fact that I referenced via a link to the full answer. This edit adds the full implementation details as part of this answer. I hope it is not too long for a SO answer.

将Xcode Bot与消息集成

在WWDC 2014 Session 415(与Xcode 6持续集成)期间,Apple演示了通过自定义集成触发器将Xcode bot与Messages应用程序集成.更具体地说,从该会话视频的23分钟标记开始( https://developer. apple.com/videos/play/wwdc2014-415/),Apple演示了结合使用集成触发器和Messages来接收构建服务器上的集成状态.此外,通过使用虚拟聊天室成员Jeeves,他们展示了直接从Messages应用程序中开始集成的能力.下面的文章提供了重现该功能的分步说明.

During WWDC 2014 Session 415, Continuous Integration with Xcode 6, Apple demonstrated integrating Xcode bots with the Messages app via custom integration triggers. More specifically, starting at the 23 minute mark of that session’s video (https://developer.apple.com/videos/play/wwdc2014-415/), Apple demonstrates the use of integration triggers in conjunction with Messages to receive the status of integrations on a build server. Furthermore, through the use of a virtual chat room member, Jeeves, they demonstrate the ability to start integrations directly from within the Messages app. The following article provides step-by-step instructions to reproduce that functionality.

客户端和服务器配置

首先,这是我用来模仿Jeeves功能的客户端和服务器的配置:

To get started, here are the configurations of the client and server I used to mimic the Jeeves functionality:

客户 OS X版本10.11(El Capitan),Xcode 7.0.1

Client OS X Version 10.11 (El Capitan), Xcode 7.0.1

服务器 OS X版本10.11(El Capitan),OS X Server 5.0.4,Xcode 7.0.1,Ruby 2.0.0p645

Server OS X Version 10.11 (El Capitan), OS X Server 5.0.4, Xcode 7.0.1, Ruby 2.0.0p645

网络 为了进行开发和持续集成,我使用了内部网络.我的OS X Server位于domain.local,而我的开发机器是同一内部网络上的另一个节点.无论您使用内部还是外部服务器,下面的说明都应该有效.

Network For my development and continuous integrations, I use an internal network. My OS X Server is at domain.local, and my development machine is another node on the same internal network. The instructions below should work regardless if you’re using an internal or external server.

Jabber –消息的基础

Jabber是用于实例消息传递的开源协议的原始名称. Jabber被重命名为可扩展消息和状态协议(XMPP). OS X Messages应用程序的核心是使用Jabber.

Jabber is the original name of an open source protocol for instance messaging. Jabber was renamed the Extensible Messaging and Presence Protocol (XMPP). The OS X Messages app is built using Jabber at its core.

为此,我们将广泛使用Jabber(消息),因此请确保它已打开.在OS X Server App中,选择服务">消息"视图,然后在右上角打开消息".对于Jeeves,我使用的Messages服务设置如下:

We’ll use Jabber (Messages) extensively in this effort, so let’s ensure it is on. From the OS X Server App, select the Services > Messages view, and toggle on Messages in the upper right corner. For Jeeves, the Messages service settings I used are as follows:

在服务器的终端窗口中,如果要检查Jabber的特定设置,请使用

From a terminal window on your server, if you want to check the specific settings for Jabber, use

$ sudo serveradmin settings jabber

尤其要注意jabberClientPortTLS(5222)和jabberClientPortSSL(5223)值.这些是服务器上用于与Jabber服务进行通信的端口.

Note in particular the jabberClientPortTLS (5222) and jabberClientPortSSL (5223) values. These are the ports on your server that you will use to communicate with the Jabber service.

我们将使用Ruby为Jeeves编写大多数脚本,并且我们需要一个XMPP/Jabber库来完成此任务.在服务器的终端窗口中,使用以下命令安装XMPP4R(Ruby的XMPP/Jabber库)

We’ll be writing most of the scripts for Jeeves using Ruby, and we’ll need a XMPP/Jabber library to accomplish this. From a terminal window on your server, install XMPP4R (an XMPP/Jabber library for Ruby) using

$ gem install xmpp4r

为Jabber服务创建用户

由于我的服务器是本地服务器,上面没有任何开发人员帐户,因此我需要为各种开发人员创建帐户以登录到Jabber.您可能需要或可能不需要此步骤,具体取决于您的服务器是否已定义了用户帐户.

Because my Server is a local server without any developer accounts on it, I needed to create accounts for various developers to login to Jabber. You may or may not need this step depending if your server already has user accounts defined.

从服务器上的OS X Server App中,转到帐户">用户"列表,然后为将要使用虚拟Jeeves助手的每个客户端添加新用户.确保为Jeeves创建一个新用户.对于用户"Tom",这是使用的设置.确保为每个用户创建一个电子邮件地址,但是邮件服务不需要运行.这些电子邮件地址将用于从客户端上的Messages App登录到Jabber服务.

From the OS X Server App on your server, go to the Accounts > Users list, and add new user for each client that will be utilizing the virtual Jeeves assistant. Be sure to create a new user for Jeeves. For user ‘Tom’, here are the settings that were used. Be sure to create an email address for each user, but the Mail service does not need to be running. These email addresses will be used to log into the Jabber service from the Messages App on your client.

从客户端开发计算机登录到Jabber

使用服务器上定义的用户帐户,现在可以从客户端计算机登录Jabber帐户了.在客户端上的消息应用程序中,转到消息>首选项>帐户.选择左下角的+号,选择其他邮件帐户...",然后按继续.在添加消息帐户"对话框中,为帐户类型选择"Jabber",然后为您的用户填写凭据信息.这是我使用的设置:

With the user account(s) defined on your server, it’s now time to login to the Jabber account from your client machine. In the Messages app on your client, go to Messages > Preferences > Accounts. Select the + sign in the lower left, select "Other Messages Account..." and press Continue. In the Add a Messages account dialog, select Jabber for the Account Type, and fill in the credential information for your user(s). Here were the settings I used:

(请注意,如果启用了SSL,则端口(5223)与您在检查服务器上的Jabber服务的设置时列出的jabberClientPortSSL值匹配.)

(Note with SSL toggled on, the Port (5223) matches the jabberClientPortSSL value you listed earlier when checking the settings of the Jabber service on your server.)

成功登录到Jabber服务后,您可以选择在Jabber帐户的聊天设置"页面下更改帐户昵称.其他所有默认设置都可以保留.

After successfully logging in to the Jabber service, you can optionally change your account nickname under the "Chat Settings" page of the Jabber account. All other default settings are okay to leave as is.

创建聊天室

我们希望所有bot集成状态以及与虚拟助手Jeeves的通信都可以通过Messages聊天室进行.聊天室可以进行群组交流,但您不需要邀请即可加入.要创建聊天室,请执行以下操作.

We want all bot integration statuses and communication to our virtual assistant, Jeeves, to be through a Messages chat room. Chat rooms allow group communication but you don’t need an invitation to join. To create the chat room, do the following.

从消息"中,选择文件">转到聊天室".您应该看到列出了登录到Jabber服务的帐户.输入Room @ name的integration @ rooms..local,然后选择转到". (请注意,我发现聊天室必须是"rooms..local" .com".使用"rooms"以外的其他字词不会创建聊天室.)

From Messages, choose File > Go to Chat Room. You should see the account you logged into the Jabber service listed. Key in integration@rooms..local for the Room Name, and select Go. (Note that I found that chat room needed to be ‘rooms..local’ .com’>. Using a word other than ‘rooms’ would not create the chat room.)

配置服务器网站服务

从客户端计算机上运行的Xcode开始集成时,集成前和集成后脚本通过对OS X Server网站服务上的文件进行http调用来与Jabber服务进行通信.您必须配置OS X Server网站服务来处理这些调用.

When an integration is started from Xcode running on your client machine, the pre- and post- integration scripts communicate with the Jabber service by making an http call to a file on the OS X Server Website Service. You must configure the OS X Server Websites service to handle these calls.

您需要修改非SSL http(端口80)网站的设置.这是我使用的设置.

You’ll need to modify the settings for the non-SSL http (port 80) site. Here are the settings I used.

选择Port 80网站,然后选择下方的铅笔图标以使您的设置与之匹配.

Select the Port 80 Website, and select the pencil icon underneath to make your settings match these.

选择编辑高级设置...",并使您的设置与这些设置匹配. (启用允许CGI执行..."将启用Ruby脚本执行.)

Select the "Edit Advanced Settings..." and make your settings match these. (Enabling "Allow CGI execution..." enables Ruby script execution.)

最后,您需要启用一个特定文件(message_room –我们将在后面讨论)以配置为以Ruby脚本运行.为此,请将以下.htaccess文件放置在Web服务器的默认主文件夹(通常为/Library/Server/Web/Data/Sites/Default)中.

Finally, you’ll need to enable a particular file (message_room – we’ll discuss later) to be configured to run as a Ruby script. To do that, place the following .htaccess file in your web server’s default home folder (typically /Library/Server/Web/Data/Sites/Default).

Options +ExecCGI 
<FilesMatch message_room$>
    SetHandler cgi-script 
</FilesMatch>

注意:在以下所有ruby脚本中,您需要修改每个脚本中"credentials"注释下的变量以匹配您的域并登录凭据.

NOTE: in all of the following ruby scripts, you’ll need to modify the variables just under the "credentials" comment in each script to match your domain, and login credentials.

集成前和集成后脚本 当我们从客户端计算机上的Xcode开始集成时,我们希望向Jabber集成聊天室发送消息,以便可以通知该聊天室的所有成员集成已经开始(和完成).在Xcode的bot触发器页面上,将以下集成前和集成后脚本添加到项目的bot中.

Pre- and Post-Integration Scripts When we start an integration from Xcode on our client machine, we want to send a message to the Jabber Integration chat room so that all members of the chat room can be notified the integration has started (and finished). Add the following pre- and post-integration scripts to your project’s bot on the bot Triggers page within Xcode.

这是集成前的触发器脚本:

This is the pre-integration Trigger script:

#!/usr/bin/env ruby 
require 'json' 
require 'net/http' 
require 'uri'

# ------------------------------------------------------------------------------------- 
# credentials and such
domain = "<yourDomain>.local"

# ------------------------------------------------------------------------------------- 
# our messaging endpoint
uri = URI.parse("http://#{domain}:80/message_room")

# ------------------------------------------------------------------------------------- 
# what we want to say
message = "#{ENV['XCS_BOT_NAME']} integration #{ENV['XCS_INTEGRATION_NUMBER']} is now starting."

# ------------------------------------------------------------------------------------- 
# build up the request body
reqBody = {:message => message}
body = JSON.generate(reqBody)

# ------------------------------------------------------------------------------------- 
# the connect type
http = Net::HTTP.new(uri.host, uri.port)

# ------------------------------------------------------------------------------------- 
# build up the request
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-type', 'application/json')
request.body = body

# ------------------------------------------------------------------------------------- 
# send the request and get the response
response = http.request(request)

这是集成后的触发器脚本:

This is the post-integration Trigger script:

#!/usr/bin/env ruby 
require 'json' 
require 'net/http' 
require 'uri'

# ------------------------------------------------------------------------------------- 
# credentials and such
domain = "<yourDomain>.local"

# ------------------------------------------------------------------------------------- 
# our messaging endpoint
uri = URI.parse("http://#{domain}:80/message_room")

# ------------------------------------------------------------------------------------- 
# what we want to say
integrationResult = case ENV['XCS_INTEGRATION_RESULT']
    when "succeeded"
        "has completed successfully."
    when "test-failures"
        tc = ENV['XCS_TEST_FAILURE_COUNT'].to_i
        "completed with #{tc} failing #{(tc ==1 ) ? 'test' : 'tests'}."
    when "build-errors"
        ec = ENV['XCS_ERROR_COUNT'].to_i
        "failed with #{ec} build #{(ec == 1) ? 'error' : 'errors'}."
    when "warnings"
        wc = ENV['XCS_WARNING_COUNT'].to_i
        "completed with #{wc} #{(wc == 1) ? 'warning' : 'warnings'}."
    when "analyzer-warnings"
        ic = ENV['XCS_ANALYZER_WARNING_COUNT'].to_i
        "completed with #{ic} static analysis #{(ic == 1) ? 'issue' : 'issues'}."
    when "trigger-error"
        "failed running trigger script."
    when "checkout-error"
        "failed to checkout from source control."
    else
        "failed with unexpected errors."
    end

message = "#{ENV['XCS_BOT_NAME']} integration #{ENV['XCS_INTEGRATION_NUMBER']} #{integrationResult}"

# ------------------------------------------------------------------------------------- 
# build up the request body
reqBody = {:message => message}
body = JSON.generate(reqBody)

# ------------------------------------------------------------------------------------- 
# the connect type
http = Net::HTTP.new(uri.host, uri.port)

# ------------------------------------------------------------------------------------- 
# build up the request
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-type', 'application/json')
request.body = body

# -------------------------------------------------------------------------------------
# send the request and get the response
response = http.request(request)

前两个Ruby脚本会调用OS X Server网站主文件夹(通常为/Library/Server/Web/Data/Sites/Default)中的message_room文件.将以下message_room文件放入该文件夹.

The prior two Ruby scripts make a call to the message_room file residing in your OS X Server Website home folder (typically /Library/Server/Web/Data/Sites/Default). Place the following message_room file into that folder.

#!/usr/bin/env ruby
require 'cgi' 
require 'json' 
require 'xmpp4r' 
require 'xmpp4r/muc'

# ------------------------------------------------------------------------------------- 
# credentials and such
domain = "<domain>.local"
userId = "jeeves@#{domain}"
userPw = "<jeevesAccountPassword>"
roomName = "integration@rooms.#{domain}"

# ------------------------------------------------------------------------------------- 
# header sent back
cgi = CGI.new
puts cgi.header( "type" => "text/html", "status" => "OK")

# ------------------------------------------------------------------------------------- 
# get the message out of the json formatted text
keyValue = JSON.parse(cgi.params.keys.first)
key = "message"
value = keyValue[key] puts value

# ------------------------------------------------------------------------------------- 
# create the message to the iChat (jabber) room
fromJID = Jabber::JID.new(userId)
jabberClient = Jabber::Client.new(fromJID)
jabberClient.connect
jabberClient.auth(userPw)
jabberClient.send(Jabber::Presence.new.set_type(:available))

# ------------------------------------------------------------------------------------- 
# send the message to a chat room
roomID = roomName + "/" + jabberClient.jid.node
roomJID = Jabber::JID::new(roomID)
room = Jabber::MUC::MUCClient.new(jabberClient) room.join(roomJID)
roomMessage = Jabber::Message.new(roomJID, value) room.send(roomMessage)

从Messages应用程序开始集成

我们希望能够从Messages App中向我们的虚拟助手Jeeves发布指令.我们将支持三个说明:

We want to be able to issue instructions to our virtual assistant Jeeves from within the Messages App. We’re going to support three instructions:

  1. Jeeves,天气#获取当前天气(不包括) zip默认为Cupertino)

  1. Jeeves, weather # gets the current weather (w/o zip defaults to Cupertino)

Jeeves,积分(Bot名称)#为给定的积分开始积分 机器人

Jeeves, integration (Bot Name) # starts an integration for the given Bot

Jeeves,退出OS X Server上的#shutdown Jeeves

Jeeves, exit # shutdown Jeeves on your OS X Server

以下文件将放置在OS X Server网站的默认文件夹(通常为/Library/Server/Web/Data/Sites/Default)中.

The following files will be placed in your OS X Server website’s default folder (typically /Library/Server/Web/Data/Sites/Default).

处理虚拟助手Jeeves的主文件是jeevesManager.rb.通过输入

The main file that handles the virtual assistant, Jeeves, is jeevesManager.rb. Start this file to wake Jeeves up by entering

$ ruby ./jeevesManager.rb

从服务器上网站的默认文件夹中获取.

from the website’s default folder on your server.

#!/usr/bin/env ruby
require 'xmpp4r'
require 'xmpp4r/muc'
require 'xmpp4r/delay'
require './jeevesWeather.rb' 
require './jeevesIntegration.rb'

# ------------------------------------------------------------------------------------- 
# credentials and such
domain = "<domain>.local"
userId = "jeeves@#{domain}"
userPw = "<jeevesAccountPassword>"
roomName = "integration@rooms.#{domain}" 
defaultWeatherZipCode = "95015"

# ------------------------------------------------------------------------------------- 
# create the client we'll use
fromJID = Jabber::JID.new(userId)
jabberClient = Jabber::Client.new(fromJID)
jabberClient.connect
jabberClient.auth(userPw)
jabberClient.send(Jabber::Presence.new.set_type(:available))

# ------------------------------------------------------------------------------------- 
# connect to the chatroom
roomID = roomName + "/" + jabberClient.jid.node
roomJID = Jabber::JID::new(roomID)
room = Jabber::MUC::MUCClient.new(jabberClient) room.join(roomJID)

# ------------------------------------------------------------------------------------- 
# weather
def getWeather(m)
    begin
        words = m.body.downcase.split("weather") 
        where = defaultWeatherZipCode
        if (words.length == 2)
            where = words[1].strip 
        end
        weather = get_weather_for_city(where,'f') 
    rescue
        weather = "Couldn't get weather for that location - try zip code" 
    end
    return weather 
end

# ------------------------------------------------------------------------------------- 
# integration
def startIntegration(m)
    begin
        words = m.body.split("integrate") 
        botName = "Invalid BOT Name"
        if (words.length == 2)
            botName = words[1].strip 
        end
        integrationMessage = jeevesIntegration(botName) 
    rescue
        integrationMessage = "Failed integrating #{botName}" 
    end
    return integrationMessage 
end

# ------------------------------------------------------------------------------------- 
# listen for messages in chatroom (this callback will run in a separate thread) 
room.add_message_callback do |m|
    if (m.x.nil?) # the msg is current 
        if m.type != :error
            body = m.body;
            if (body.downcase.include? "jeeves")

                # assume Jeeves does not understand command
                understood = 0

                # exit Jeeves
                if (body.downcase.include? "exit") 
                    understood = 1
                    message = "Good-bye"
                    mainthread.wakeup
                end

                # Weather
                if (body.downcase.include? "weather") 
                    understood = 1
                    message = getWeather(m) 
                end

                # Integrate BOT
                if (body.downcase.include? "integrate") 
                    understood = 1
                    message = startIntegration(m) 
                end

                # Jeeves doesn't understand command
                if (understood == 0)
                    message = "I don't understand that command!"
                end

                # let user know what has happened
                roomMessage = Jabber::Message.new(roomJID, message)
                room.send(roomMessage)
            end
        end
    end
end


# ------------------------------------------------------------------------------------- 
# add the callback to respond to server ping (to keep the connect alive)
jabberClient.add_iq_callback do |iq_received|
    if iq_received.type == :get
        if iq_received.queryns.to_s != 'http://jabber.org/protocol/disco#info'
            iq = Jabber::Iq.new(:result, jabberClient.jid.node) 
            iq.id = iq_received.id
            iq.from = iq_received.to
            iq.to = iq_received.from
            jabberClient.send(iq) 
        end
    end 
end

# ------------------------------------------------------------------------------------- 
# stop the main thread (the call back will still be alive this way)
print "Connected to chat room...\n"
Thread.stop
print "Disconnected from chat room...\n"

# leave chat room and log out of Jabber
room.exit 
jabberClient.close

上面的Jeeves管理器文件还使用了另外两个补充文件.下面的第一个处理获取天气预报并将其格式化,第二个处理开始集成.

Two other supplemental files are utilized by the Jeeves manager file above. The first one below handles getting the weather forecast and formatting it, and the second handles starting an integration.

######### Weather #########
require 'rexml/document' 
require 'open-uri' 
require 'net/smtp'

# ------------------------------------------------------------------------------------- 
# yahoo weather url info
# http://developer.yahoo.net/weather/#examples

# ------------------------------------------------------------------------------------- 
#Returns a hash containing the location and temperature information
#Accepts US zip codes or Yahoo location id's
def yahoo_weather_query(loc_id, units)
    h = {}
    open("http://xml.weather.yahoo.com/forecastrss?p=#{loc_id}&u=#{units}") do |http|
    response = http.read
    doc = REXML::Document.new(response)
    root = doc.root
    channel = root.elements['channel']
    location = channel.elements['yweather:location']
    h[:city] = location.attributes["city"]
    h[:region] = location.attributes["region"]
    h[:country] = location.attributes["country"]
    h[:temp] = channel.elements["item"].elements["yweather:condition"].attributes["temp"]         
    h[:text] = channel.elements["item"].elements["yweather:condition"].attributes["text"] 
    h[:wind_speed] = channel.elements['yweather:wind'].attributes['speed']
    h[:humidity] = channel.elements['yweather:atmosphere'].attributes['humidity'] 
    h[:sunrise] = channel.elements['yweather:astronomy'].attributes['sunrise']
    h[:sunset] = channel.elements['yweather:astronomy'].attributes['sunset']
    h[:forecast_low] = channel.elements["item"].elements['yweather:forecast'].attributes['low']
    h[:forecast_high] = channel.elements["item"].elements['yweather:forecast'].attributes['high'] end
    return h
end

# -------------------------------------------------------------------------------------
def get_weather_for_city(city_code,units)
    weather_info = yahoo_weather_query(city_code, units)
    city = weather_info[:city]
    region = weather_info[:region]
    country = weather_info[:country]
    temp = weather_info[:temp]
    wind_speed = weather_info[:wind_speed]
    humidity = weather_info[:humidity]
    text = weather_info[:text]
    sunrise = weather_info[:sunrise]
    sunset = weather_info[:sunset]
    forecast_low = weather_info[:forecast_low] 
    forecast_high = weather_info[:forecast_high]

    return "#{city}, #{region}:\n" + " Currently #{temp} degrees, #{humidity}% humidity, #{wind_speed} mph winds, #{text}.\n" + " Forecast: #{forecast_low} low, #{forecast_high} high.\n" + " Sunrise: #{sunrise}, sunset: #{sunset}.\n"
end

最后,这是启动Messages应用程序集成的脚本

Finally, this is the script that kicks off an integration from Messages app

require 'json' 
require 'open-uri' 
require 'openssl'

# -------------------------------------------------------------------------------------
def jeevesIntegration(botToIntegrate)

    # credentials
    domain = "<domain>.local"
    endpoint = "https://#{domain}:20343"
    user = "your-integration-username (not Jeeves)" 
    password = "password"

    # return message
    message = "Bot '#{botToIntegrate}' does not exist on server #{domain}"

    # request JSON construct with all the BOTS
    botsRequestURI = URI.parse("#{endpoint}/api/bots")
    output = open(botsRequestURI, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}) 
    bots = JSON.parse(output.readlines.join(""))

    # loop through full list of BOTS for the one we're interested in
    bots['results'].each do |bot| 
        botName = bot['name']
        if (botName.downcase == botToIntegrate.downcase) 
            botID = bot['_id']

            # curl -k -X POST -u "#{user}:#{password}" "#{endpoint}/api/bots/#{botid}/integrations" -i

            # ------------------------------------------------------------------- 
            # kickoff integration
            uri = URI.parse(endpoint)
            http = Net::HTTP.new(uri.host, uri.port)
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
            request = Net::HTTP::Post.new("/api/bots/#{botID}/integrations")
            request.basic_auth(user, password)
            response = http.request(request)
            message = "Integrating #{botName} on server #{domain}" 
        end
    end

    return message 
end

这篇关于手动启动Xcode Bot集成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆