-
Notifications
You must be signed in to change notification settings - Fork 71
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
HipChat Support #1012
HipChat Support #1012
Conversation
+1 |
Thanks to @pjmorr for testing HipChat support w/his private HipChat server |
* Moved chat adapter code into dedicated supervisor * Added the romeo XMPP library as a dep * Made startup of slack and romeo dependent on whether or not Cog.Chat.Slack.Provider and/or Cog.Chat.HipChat.Provider are enabled. * Support for: - Presence events - Accepting room invitations
- DMs detected and handled appropriately - Public MUC room invites work - @-mentioning Cog in a public MUC room works
- User and room caches extracted into separate modules - Basic Greenbar directives processor - Posting room and user messages via HipChat's V2 API
* Added support for Greenbar tables * Removed quick_lookup functions as they could race with HipChat connector initialization and return false negatives.
else | ||
nil | ||
else | ||
updated = Regex.replace(~r/^#{Regex.escape(String.downcase(bot_name))}/, text, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do this is the regex to save some duplication?
~r/(^#{Regex.escape(bot_name)})|(^#{Regex.escape(String.downcase(bot_name))})/
GenServer.call(__MODULE__, {:call_connector, {:lookup_user_jid, handle}}, :infinity) | ||
else | ||
GenServer.call(__MODULE__, {:call_connector, {:lookup_user_handle, handle}}, :infinity) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it behoove us to change the api for lookup_user
to work like lookup_room
? Maybe worth adding a issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Add a ticket and tag it with the 0.16 milestone.
Suite is patterned after the Slack tests.
Look up bot user in the XMPP roster and use the corresponding name for room joins.
1e1b77b
to
0b8a3af
Compare
api_token: System.get_env("HIPCHAT_API_TOKEN"), | ||
nickname: System.get_env("HIPCHAT_NICKNAME"), | ||
jabber_id: System.get_env("HIPCHAT_JABBER_ID"), | ||
jabber_password: System.get_env("HIPCHAT_JABBER_PASSWORD") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is the same as the config changes in config/test.exs
. Is this something we could put in the base config/config.exs
instead?
@@ -13,9 +13,19 @@ config :cog, | |||
:template_cache_ttl, {1, :sec} | |||
|
|||
config :cog, Cog.Chat.Adapter, | |||
providers: [slack: Cog.Chat.Slack.Provider], | |||
providers: [#slack: Cog.Chat.Slack.Provider, | |||
hipchat: Cog.Chat.HipChat.Provider], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we'll fix this up before merging with an env var or something. Just a friendly reminder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah. Joys of poking at $NEW_FEATURE
locally.....
Will fix.
else | ||
nil | ||
else | ||
updated = Regex.replace(~r/^#{Regex.escape(String.downcase(bot_name))}/, text, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can assume that case doesn't matter here a case insensitive regex (/i
suffix) might allow you to collapse these two code branches nicely.
url = Enum.join([state.api_root, "room", room.secondary_id, "notification"], "/") <> "?token=#{state.api_token}" | ||
response = HTTPotion.post(url, headers: ["Content-Type": "application/json", | ||
"Accepts": "application/json", | ||
"Authorization": "Bearer #{state.api_token}"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to set the token as a query param and a header? That's kinda weird.
response = HTTPotion.post(url, headers: ["Content-Type": "application/json", | ||
"Accepts": "application/json", | ||
"Authorization": "Bearer #{state.api_token}"], | ||
body: body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also be nice to wrap up this request stuff into a helper function. Totally not necessary though.
def get_provider_state(name, default \\ %{}) when is_binary(name) do | ||
case Repo.get_by!(ChatProvider, name: name) do | ||
nil -> | ||
nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC Repo.get_by!
can't ever return nil
.
- Extracted Slack and HipChat config into dedicated files - Removed existing HipChat and Slack config from `(dev,test,prod).exs`
adce384
to
9e98970
Compare
9e98970
to
5773f26
Compare
Added randomized waits around all Slack API calls to reduce the likelihood of Slack's API throttling kicking in.
test/commands/*.exs are also skipped until we can suss out what is making ExVCR so grumpy.
- Restarts only the Cog.Chat.Adapter process instead of the entire Cog application tree - Added randomized pauses around all Slack API calls to avoid throttling
- Moved integration and unit tests into separate make targets
This PR reinstates HipChat support on top of the new chat provider API.
AdapterCase
and provider-specific helper modules withProviderCase
and provider-specific stateful testing client to simplify integration testing. Tests will wait for an appropriate reply from Cog instead of polling chat history.Fixes #968