Skip to content
This repository was archived by the owner on Sep 26, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packs/yammer/README.md
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.
12 changes: 12 additions & 0 deletions packs/yammer/actions/authenticate.py
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}
6 changes: 6 additions & 0 deletions packs/yammer/actions/authenticate.yaml
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.
30 changes: 30 additions & 0 deletions packs/yammer/actions/lib/actions.py
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)
12 changes: 12 additions & 0 deletions packs/yammer/actions/like_message.py
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
11 changes: 11 additions & 0 deletions packs/yammer/actions/like_message.yaml
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
12 changes: 12 additions & 0 deletions packs/yammer/actions/list_messages.py
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
6 changes: 6 additions & 0 deletions packs/yammer/actions/list_messages.yaml
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
12 changes: 12 additions & 0 deletions packs/yammer/actions/list_messages_from_user.py
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
11 changes: 11 additions & 0 deletions packs/yammer/actions/list_messages_from_user.yaml
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
12 changes: 12 additions & 0 deletions packs/yammer/actions/list_messages_my_feed.py
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
6 changes: 6 additions & 0 deletions packs/yammer/actions/list_messages_my_feed.yaml
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
13 changes: 13 additions & 0 deletions packs/yammer/actions/post_message.py
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):
Copy link
Member

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).

yammer = self.authenticate()
return yammer.messages.create(
message, group_id=group_id,
topics=topics, replied_to_id=replied_to_id)
27 changes: 27 additions & 0 deletions packs/yammer/actions/post_message.yaml
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:
Copy link
Member

Choose a reason for hiding this comment

The 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
4 changes: 4 additions & 0 deletions packs/yammer/config.yaml
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
Binary file added packs/yammer/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packs/yammer/pack.yaml
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
1 change: 1 addition & 0 deletions packs/yammer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yampy