Created
January 20, 2016 21:32
-
-
Save lidopaglia/a87ac1e7b535dd95c81b to your computer and use it in GitHub Desktop.
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
# Gets a list of open cards in a Trello board, selects a | |
# random one, and posts to slack as a lunch recommendation. | |
Import-Module SlackPS | |
# Slack | |
$slack_uri='<your_webhook_uri_here>' | |
$slack_channel = '<your_channel_here>' | |
# Trello | |
$token='<your_trello_token>' | |
$key='<your_trello_key>' | |
$board_id='<your_trello_board-id>' | |
#To find your Trello board id: | |
#$boards = Invoke-RestMethod ("https://api.trello.com/1/members/my/boards/?token=$token&key=$key") | |
$cards = @() | |
$api = Invoke-RestMethod "https://api.trello.com/1/boards/$board_id`?token=$token&key=$key&lists=open&cards=open" | |
$exclude=@(<any_lists_to_exclude>) | |
$lists = $api.lists.where({$_.name -notin $exclude}) | |
foreach($list in $lists.id) { | |
$cards += (Invoke-RestMethod "https://api.trello.com/1/lists/$list`?fields=name&cards=open&card_fields=name&key=$key&token=$token") | |
} | |
$random_card = $cards.cards | Get-Random -Count 1 | |
$suggestion = Invoke-RestMethod "https://api.trello.com/1/cards/$($random_card.id)?key=$key&token=$token" | |
#region Send to slack | |
$slackParams = @{ | |
Uri = $slack_uri | |
Channel = $slack_channel | |
Message = "May I recommend $($suggestion.name) for lunch today? $($suggestion.shortUrl)" | |
Username = 'ChefBot' | |
Emoji = 'fork_and_knife' | |
} | |
Send-SlackMessage @slackParams | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment