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

HipChat Support #1012

Merged
merged 31 commits into from
Oct 6, 2016
Merged

HipChat Support #1012

merged 31 commits into from
Oct 6, 2016

Conversation

kevsmith
Copy link
Member

@kevsmith kevsmith commented Oct 5, 2016

This PR reinstates HipChat support on top of the new chat provider API.

  • Supports DMs, rooms, and private rooms
  • Supports both @ mentions and spoken commands
  • Full support for Greenbar templates
  • Replaced AdapterCase and provider-specific helper modules with ProviderCase 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

@kevsmith kevsmith added the review label Oct 5, 2016
@pjmorr
Copy link

pjmorr commented Oct 5, 2016

+1

@kevsmith
Copy link
Member Author

kevsmith commented Oct 5, 2016

Thanks to @pjmorr for testing HipChat support w/his private HipChat server

Kevin Smith added 14 commits October 5, 2016 15:27
* 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, "")
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Kevin Smith added 3 commits October 5, 2016 15:29
Suite is patterned after the Slack tests.
Look up bot user in the XMPP roster and use the corresponding
name for room joins.
@kevsmith kevsmith force-pushed the kevsmith/hipchat-WIP branch from 1e1b77b to 0b8a3af Compare October 5, 2016 19:31
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")
Copy link
Member

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],
Copy link
Member

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.

Copy link
Member Author

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, "")
Copy link
Member

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}"],
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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.

Kevin Smith added 5 commits October 5, 2016 15:47
- Extracted Slack and HipChat config into dedicated files
- Removed existing HipChat and Slack config from `(dev,test,prod).exs`
@kevsmith kevsmith force-pushed the kevsmith/hipchat-WIP branch from adce384 to 9e98970 Compare October 5, 2016 21:05
@kevsmith kevsmith force-pushed the kevsmith/hipchat-WIP branch from 9e98970 to 5773f26 Compare October 5, 2016 21:26
Kevin Smith added 8 commits October 6, 2016 13:54
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
@kevsmith kevsmith merged commit f81973d into master Oct 6, 2016
@kevsmith kevsmith removed the review label Oct 6, 2016
@kevsmith kevsmith deleted the kevsmith/hipchat-WIP branch October 6, 2016 20:16
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

Successfully merging this pull request may close these issues.

4 participants