Use generic messages API for Zulip
It is now available to bots, so there is no need for the custom discourse endpoint any more :)
This commit is contained in:
parent
e3f09d8eb5
commit
9b229b63f9
|
@ -61,6 +61,7 @@ en:
|
|||
#######################################
|
||||
chat_integration_zulip_enabled: "Enable the Matrix chat integration provider"
|
||||
chat_integration_zulip_server: "The base URL for your Zulip server. Make sure to include http(s)://"
|
||||
chat_integration_zulip_bot_email_address: "The email address associated with your Zulip bot"
|
||||
chat_integration_zulip_bot_api_key: "The API key for your Zulip bot"
|
||||
chat_integration_zulip_excerpt_length: "Zulip post excerpt length"
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ plugins:
|
|||
default: false
|
||||
chat_integration_zulip_server:
|
||||
default: ''
|
||||
chat_integration_zulip_bot_email_address:
|
||||
default: ''
|
||||
chat_integration_zulip_bot_api_key:
|
||||
default: ''
|
||||
chat_integration_zulip_excerpt_length:
|
||||
|
|
|
@ -9,13 +9,14 @@ module DiscourseChat
|
|||
]
|
||||
|
||||
def self.send_message(message)
|
||||
uri = URI("#{SiteSetting.chat_integration_zulip_server}/api/v1/external/discourse?api_key=#{SiteSetting.chat_integration_zulip_bot_api_key}")
|
||||
uri = URI("#{SiteSetting.chat_integration_zulip_server}/api/v1/messages")
|
||||
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.use_ssl = (uri.scheme == 'https')
|
||||
|
||||
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
||||
req.body = message.to_json
|
||||
req = Net::HTTP::Post.new(uri)
|
||||
req.basic_auth(SiteSetting.chat_integration_zulip_bot_email_address, SiteSetting.chat_integration_zulip_bot_api_key)
|
||||
req.set_form_data(message)
|
||||
|
||||
response = http.request(req)
|
||||
|
||||
|
@ -36,9 +37,10 @@ module DiscourseChat
|
|||
excerpt: post.excerpt(SiteSetting.chat_integration_zulip_excerpt_length, text_entities: true, strip_links: true, remap_emoji: true))
|
||||
|
||||
data = {
|
||||
stream: stream,
|
||||
type: 'stream',
|
||||
to: stream,
|
||||
subject: subject,
|
||||
message: message
|
||||
content: message
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -7,19 +7,20 @@ RSpec.describe DiscourseChat::Provider::ZulipProvider do
|
|||
before do
|
||||
SiteSetting.chat_integration_zulip_enabled = true
|
||||
SiteSetting.chat_integration_zulip_server = "https://hello.world"
|
||||
SiteSetting.chat_integration_zulip_bot_email_address = "some_bot@example.com"
|
||||
SiteSetting.chat_integration_zulip_bot_api_key = "secret"
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'zulip', data: { stream: "general", subject: "Discourse Notifications" }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/external/discourse?api_key=secret').to_return(status: 200)
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/messages').to_return(status: 200)
|
||||
described_class.trigger_notification(post, chan1)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
||||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/external/discourse?api_key=secret').to_return(status: 400, body: '{}')
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/messages').to_return(status: 400, body: '{}')
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
|
|
Loading…
Reference in New Issue