This repository was archived by the owner on Sep 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Feature/yammer pack #314
Merged
Merged
Feature/yammer pack #314
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d43afae
Initial construct for a yammer pack
tonybaloney 33196c0
Setup some actions for messages
tonybaloney 90ae279
Actions for post_message, like_message and updated README.
tonybaloney e9c449f
pack icon
tonybaloney bd4b789
little bit of tidy up
tonybaloney 016c96d
Removed blank line
tonybaloney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Yammer Integration Pack | ||
|
|
||
| This integration pack allows you to integrate with | ||
| [Yammer](http://yammer.com/), | ||
| the Enterprise Social Network. | ||
|
|
||
| ## Actions | ||
|
|
||
| Currently, the following actions listed bellow are supported: | ||
|
|
||
| * `authenticate` - Get an authentication URL for the application, use this in a browser to gain a code. Put this code in config.yaml | ||
| * `list_messages` - List all messages | ||
| * `list_messages_from_user` - List all messages from a particular user | ||
| * `list_messages_my_feed` - List messages for my feed | ||
| * `like_message` - Like a particular message | ||
| * `post_message` - Post a message to a user, a group or a topic | ||
|
|
||
| ## Configuration | ||
|
|
||
| Update config.yaml to setup the connection to Yammer. | ||
|
|
||
| * `client_id` - The client ID provided by Yammer for your app | ||
| * `client_secret` - The client secret provided by Yammer for your app | ||
| * `expected_redirect` - The redirect Yammer expects to send you to, configured below. | ||
| * `access_code` - The code generated by viewing the URL provided when running `authenticate` | ||
|
|
||
| in Yammer you need to setup a client application on (https://www.yammer.com/client_applications) and use the details provided for your configuration. | ||
|
|
||
| Once you configure those details in config.yaml, run the `authenticate` action, which will give you a URL. Navigate to that URL in a browser and login to Yammer. | ||
| This will give you a code, which you can use in config.yaml to enable the rest of the integration. |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'AuthenticateAction' | ||
| ] | ||
|
|
||
|
|
||
| class AuthenticateAction(YammerAction): | ||
| def run(self): | ||
| auth_url = self.authenticator.authorization_url( | ||
| redirect_uri=self.expected_redirect) | ||
| return {"url": auth_url} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| name: authenticate | ||
| runner_type: python-script | ||
| description: Requests a OAuth authorization URL from the Yammer API, use this URL to authenticate your app in a browser, use the code in config.yaml | ||
| enabled: true | ||
| entry_point: authenticate.py |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| try: | ||
| import yampy | ||
| except ImportError: | ||
| message = ('Missing "yampy", please install it using pip:\n' | ||
| 'pip install yampy') | ||
| raise ImportError(message) | ||
|
|
||
| from st2actions.runners.pythonrunner import Action | ||
|
|
||
| __all__ = [ | ||
| 'YammerAction', | ||
| ] | ||
|
|
||
|
|
||
| class YammerAction(Action): | ||
| def __init__(self, config): | ||
| super(YammerAction, self).__init__(config) | ||
| self.client_id = self.config['client_id'] | ||
| self.client_secret = self.config['client_secret'] | ||
| self.expected_redirect = self.config['expected_redirect'] | ||
| self.authenticator = yampy.Authenticator( | ||
| client_id=self.client_id, | ||
| client_secret=self.client_secret) | ||
| self.access_code = self.config['access_code'] | ||
| self.user_info = None | ||
| self.network_info = None | ||
|
|
||
| def authenticate(self): | ||
| access_token = self.authenticator.fetch_access_token(self.access_code) | ||
| return yampy.Yammer(access_token=access_token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'LikeMessageAction' | ||
| ] | ||
|
|
||
|
|
||
| class LikeMessageAction(YammerAction): | ||
| def run(self, message_id): | ||
| yammer = self.authenticate() | ||
| messages = yammer.messages.like(message_id) | ||
| return messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| name: like_message | ||
| runner_type: python-script | ||
| description: Like a particular message | ||
| enabled: true | ||
| entry_point: like_message.py | ||
| parameters: | ||
| message_id: | ||
| type: string | ||
| description: The message ID to like | ||
| required: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'ListMessagesAction' | ||
| ] | ||
|
|
||
|
|
||
| class ListMessagesAction(YammerAction): | ||
| def run(self): | ||
| yammer = self.authenticate() | ||
| messages = yammer.messages.all() | ||
| return messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| name: list_messages | ||
| runner_type: python-script | ||
| description: List all messages globally for the authenticated user | ||
| enabled: true | ||
| entry_point: list_messages.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'ListMessagesFromUserAction' | ||
| ] | ||
|
|
||
|
|
||
| class ListMessagesFromUserAction(YammerAction): | ||
| def run(self, user_id): | ||
| yammer = self.authenticate() | ||
| messages = yammer.messages.from_user(user_id) | ||
| return messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| name: list_messages_from_user | ||
| runner_type: python-script | ||
| description: List all messages from my feed for the authenticated user | ||
| enabled: true | ||
| entry_point: list_messages_from_user.py | ||
| parameters: | ||
| user_id: | ||
| type: string | ||
| description: the user ID to show messages from | ||
| required: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'ListMessagesMyFeedAction' | ||
| ] | ||
|
|
||
|
|
||
| class ListMessagesMyFeedAction(YammerAction): | ||
| def run(self): | ||
| yammer = self.authenticate() | ||
| messages = yammer.messages.from_my_feed() | ||
| return messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| name: list_messages_my_feed | ||
| runner_type: python-script | ||
| description: List all messages from my feed for the authenticated user | ||
| enabled: true | ||
| entry_point: list_messages_my_feed.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from lib.actions import YammerAction | ||
|
|
||
| __all__ = [ | ||
| 'PostMessageAction' | ||
| ] | ||
|
|
||
|
|
||
| class PostMessageAction(YammerAction): | ||
| def run(self, message, group_id, topics, replied_to_id): | ||
| yammer = self.authenticate() | ||
| return yammer.messages.create( | ||
| message, group_id=group_id, | ||
| topics=topics, replied_to_id=replied_to_id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| name: post_message | ||
| runner_type: python-script | ||
| description: List all messages from my feed for the authenticated user | ||
| enabled: true | ||
| entry_point: post_message.py | ||
| parameters: | ||
| message: | ||
| type: string | ||
| description: The message | ||
| required: true | ||
| group_id: | ||
| type: string | ||
| description: The ID of the group to post the message to | ||
| required: true | ||
| topics: | ||
| type: array | ||
| description: A list of topics for the message | ||
| required: false | ||
| replied_to_id: | ||
| type: string | ||
| description: The message ID this is in response to | ||
| required: false | ||
| direct_to_id: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor thing - just noticed this argument is not actually used in the action. |
||
| type: string | ||
| description: Sends the message as a private message to the user ID specified | ||
| required: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| client_id: xCB9j23gnDFBDFG | ||
| client_secret: 12fjf9usdfij1oj | ||
| access_code: 1234567890 | ||
| expected_redirect: https://my-url.com |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| name : yammer | ||
| description : st2 content pack containing yammer integrations | ||
| keywords: | ||
| - yammer | ||
| - chatops | ||
| - social | ||
| version : 0.1 | ||
| author : Anthony Shaw | ||
| email : anthony.shaw@dimensiondata.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| yampy |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Minor thing - you can also default all the optional arguments to None (topics, group_id, replied_to_id).