LoginSignup
0
0

More than 1 year has passed since last update.

#Slack で画像をアップロードすると #Twitter にもアップロードする例 by #Zapier + #python

Last updated at Posted at 2019-03-14

  • Zapierの通常トリガー、アクションだけでは完結できないので python を使う
  • Slack側で public share image 設定をする必要がある
  • Slack の pemalink public が 画像じゃなくて HTMLなので、その中から画像URLを抽出して使う

Slack の New File をトリガーにする

image

Code by Zapier で python を走らせる

Slackの 情報を input に入れる
Slack の OAuth token はべた書きする

image

out = {}

import requests, os, re

token = input_data['token']
channel = input['channel_id']

file_id = input['file_id']

share_api_url ='https://slack.com/api/files.sharedPublicURL?token=' + token + '&file=' + file_id + '&pretty=1'

share_api_res = requests.get(share_api_url)
out['share_api_results'] = share_api_res.json()

permalink_public_res = requests.get(input['permalink_public'])
match = re.search(r'<img src="([^\s]+?)">', permalink_public_res.text)

out['public_image_url'] = match[1]


output = [out]

Twitter の Create Image Tweet をアクションにする

image

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0