2021年6月9日水曜日

Blogger の投稿を Integromat でツイートする Ver.2

Ver.1 の紹介記事を書いた気がしてたのですがなかったので、
まずは概要を紹介します。
Integromat とは
Intergromat は IFTTT みたいなやつ(iPaaS/RPA)です。
様々サービスのイベントをトリガーに他サービスと連携することができるものです。
操作の自動化をする RPA ツールとはちょっと違うので注意してください。
詳しいことは拙著を見てね^^
「詳解Integromat iPaaS完全入門」

Blogger で記事公開したらツイートするシナリオ
Integromat を使って「ブログズミ」で更新があったら Twitter にツイートするシナリオを活用しています。
注意: 現在 Integromat の Twitter App は有料プランの登録が必要です
Blogger は RSS フィードがあるのでそれをトリガーにツイートするシナリオになっています。
私が使っているシナリオは間にいくつかステップがありますが、単純にツイートするだけであれば、RSS の情報からツイート本文を書くだけでシナリオが作れると思います。

Ver.2 で変わったところ
Blogger のラベルをツイートのタグに変換
ツイートにタグをつけるようにしました。
ラベル→タグ変換は以下の2つのモジュールで行いました。


最初の Tools モジュールでラベルの配列に「 #」を追加しつつ、1つの文字列にしています。
「{{replace("#" + join(1.labels; space + "#"); ":"; space)}}」
「#Re:VIEW」 のような記号を含むものは記号より後ろがタグとして認識されないので、ここで空白スペースに置換もしています。(「:」のみ対応)

次に Text parser モジュールでタグとタグの間のスペース以外のスペースを削除します。
「s/\s([^#])/$1/g」

これだけではわかりにくいので、実際に処理されたときの様子を見てみましょう。

入力されたラベルは以下の図の通りです。
ここでは「Re:VIEW Starter」のラベルに着目しましょう。

Tools モジュールによって「#Re View Starter」と変換されます。

最後に Text parser で「#ReViewStarter」となります。


あとは、加工済みのテキストを Twitter モジュールで使うだけです。
新規公開か追記かの判定
追記があった場合は RSS フィードの公開日と更新日が入ってるので、それぞれの時間を比較して判定しています。
まず、Tools モジュールで公開日・更新日に setSecond をして 0:00 の時刻に揃えます。
「{{setSecond(1.dateUpdated; 0)}}」

そして、公開日と更新日が同じなら新規投稿、更新日が新しい場合は追記として分岐します。
Blueprint
最後にシナリオの Blueprint を公開します。
※Blueprint は有償機能です
※インポートしてもコネクションは筆者 organization の ID になっているので付け替え必須


{
"name": "Integration Blogger, Twitter",
"flow": [
{
"id": 1,
"module": "blogger:TriggerNewPost",
"version": 4,
"parameters": {
"blogId": "1887782251735454807",
"labels": [],
"status": "onlyLive",
"account": 397330,
"maxResults": 5
},
"mapper": {},
"metadata": {
"designer": {
"x": 0,
"y": 300
},
"restore": {
"blogId": {
"label": "ブログズミ"
},
"labels": {
"items": []
},
"status": {
"label": "Only live"
},
"account": {
"label": "My Google connection"
}
},
"parameters": [
{
"name": "account",
"type": "account",
"label": "Connection",
"required": true
},
{
"name": "status",
"type": "select",
"label": "Status",
"required": true,
"validate": {
"enum": [
"onlyLive",
"onlyScheduled",
"onlyDraft"
]
}
},
{
"name": "maxResults",
"type": "number",
"label": "Maximum number of results",
"required": true
},
{
"name": "labels",
"spec": {
"name": " ",
"type": "text",
"label": "Label"
},
"type": "array",
"label": "Labels",
"labels": {
"add": "Add a label",
"edit": "Edit a label"
}
},
{
"name": "blogId",
"type": "select",
"label": "Blog",
"required": true
}
],
"advanced": true
},
"onerror": [
{
"id": 24,
"module": "builtin:Ignore",
"version": 1,
"metadata": {
"designer": {
"x": 300,
"y": 600
}
}
}
]
},
{
"id": 25,
"module": "util:SetVariables",
"version": 1,
"parameters": {},
"mapper": {
"scope": "roundtrip",
"variables": [
{
"name": "published_t",
"value": "{{setSecond(1.datePublished; 0)}}"
},
{
"name": "update_t",
"value": "{{setSecond(1.dateUpdated; 0)}}"
},
{
"name": "tags",
"value": "{{replace(\"#\" + join(1.labels; space + \"#\"); \":\"; space)}}"
}
]
},
"metadata": {
"designer": {
"x": 300,
"y": 150
},
"restore": {
"scope": {
"label": "One cycle"
},
"variables": {
"items": [
"undefined",
"undefined",
"undefined"
]
}
},
"expect": [
{
"name": "variables",
"spec": [
{
"name": "name",
"type": "text",
"label": "Variable name",
"required": true
},
{
"name": "value",
"type": "any",
"label": "Variable value"
}
],
"type": "array",
"label": "Variables"
},
{
"name": "scope",
"type": "select",
"label": "Variable lifetime",
"required": true,
"validate": {
"enum": [
"roundtrip",
"execution"
]
}
}
],
"interface": [
{
"name": "published_t",
"type": "any",
"label": "published_t"
},
{
"name": "update_t",
"type": "any",
"label": "update_t"
},
{
"name": "tags",
"type": "any",
"label": "tags"
}
]
}
},
{
"id": 23,
"module": "regexp:Replace",
"version": 1,
"parameters": {},
"filter": {
"name": "is_not_too_old",
"conditions": [
[
{
"a": "{{25.published_t}}",
"b": "{{addYears(timestamp; -3)}}",
"o": "date:greater"
}
]
]
},
"mapper": {
"text": "{{25.tags}}",
"value": "$1",
"global": true,
"pattern": "\\s([^#])",
"multiline": false,
"sensitive": true,
"singleline": false
},
"metadata": {
"designer": {
"x": 600,
"y": 150
},
"restore": {
"global": {
"mode": "chose"
},
"multiline": {
"mode": "chose"
},
"sensitive": {
"mode": "chose"
},
"singleline": {
"mode": "chose"
}
},
"expect": [
{
"name": "pattern",
"type": "text",
"label": "Pattern",
"required": true
},
{
"name": "value",
"type": "text",
"label": "New value"
},
{
"name": "global",
"type": "boolean",
"label": "Global match",
"required": true
},
{
"name": "sensitive",
"type": "boolean",
"label": "Case sensitive",
"required": true
},
{
"name": "multiline",
"type": "boolean",
"label": "Multiline",
"required": true
},
{
"name": "singleline",
"type": "boolean",
"label": "Singleline",
"required": true
},
{
"name": "text",
"type": "text",
"label": "Text"
}
]
}
},
{
"id": 4,
"module": "builtin:BasicRouter",
"version": 1,
"filter": {
"name": "test",
"conditions": [
[
{
"a": "1",
"b": "1",
"o": "text:equal"
}
]
]
},
"mapper": null,
"metadata": {
"designer": {
"x": 900,
"y": 150
}
},
"routes": [
{
"flow": [
{
"id": 17,
"module": "twitter:createTweet",
"version": 5,
"parameters": {
"__IMTCONN__": 394960
},
"filter": {
"name": "is_new",
"conditions": [
[
{
"a": "{{25.published_t}}",
"b": "{{25.update_t}}",
"o": "number:equal"
}
]
]
},
"mapper": {
"select": "image",
"status": "ブログ更新。\nブログズミ: {{1.title}}\n{{1.url}}\n{{23.text}}",
"possibly_sensitive": false,
"display_coordinates": true
},
"metadata": {
"designer": {
"x": 1200,
"y": 0
},
"restore": {
"select": {
"label": "Image or GIF"
},
"__IMTCONN__": {
"label": "srz_zumix (Z.Z.ずみっくす)"
},
"attachments": {
"mode": "chose",
"items": []
},
"display_coordinates": {
"mode": "chose"
}
},
"parameters": [
{
"name": "__IMTCONN__",
"type": "account",
"label": "Connection",
"required": true
}
],
"expect": [
{
"name": "status",
"type": "text",
"label": "Status",
"required": true
},
{
"name": "select",
"type": "select",
"label": "Upload",
"validate": {
"enum": [
"image",
"video"
]
}
},
{
"name": "possibly_sensitive",
"type": "boolean",
"label": "Attached images contain sensitive content (nudity, violence, etc).",
"required": true
},
{
"name": "lat",
"type": "number",
"label": "Geographic Latitude",
"validate": {
"max": 90,
"min": -90
}
},
{
"name": "long",
"type": "number",
"label": "Geographic Longitude",
"validate": {
"max": 180,
"min": -180
}
},
{
"name": "display_coordinates",
"type": "boolean",
"label": "Display tweets coordinates",
"required": true
},
{
"name": "attachments",
"spec": [
{
"name": "filename",
"type": "filename",
"label": "File Name",
"semantic": "file:name"
},
{
"name": "data",
"type": "buffer",
"label": "Data",
"semantic": "file:data"
},
{
"name": "media_category",
"type": "select",
"label": "Media Category",
"options": [
{
"label": "Tweet Gif",
"value": "tweet_gif"
},
{
"label": "Tweet Image",
"value": "tweet_image"
}
]
}
],
"type": "array",
"label": "Attachments",
"validate": {
"maxItems": 4
}
}
],
"advanced": true
}
}
]
},
{
"flow": [
{
"id": 18,
"module": "twitter:createTweet",
"version": 5,
"parameters": {
"__IMTCONN__": 394960
},
"filter": {
"name": "is_update",
"conditions": [
[
{
"a": "{{25.published_t}}",
"b": "{{25.update_t}}",
"o": "date:less"
}
]
]
},
"mapper": {
"select": "image",
"status": "ブログ内容の更新をしました\nブログズミ: {{1.title}}\n{{1.url}}\n{{23.text}}",
"possibly_sensitive": false,
"display_coordinates": true
},
"metadata": {
"designer": {
"x": 1200,
"y": 300
},
"restore": {
"select": {
"label": "Image or GIF"
},
"__IMTCONN__": {
"label": "srz_zumix (Z.Z.ずみっくす)"
},
"attachments": {
"mode": "chose",
"items": []
},
"display_coordinates": {
"mode": "chose"
}
},
"parameters": [
{
"name": "__IMTCONN__",
"type": "account",
"label": "Connection",
"required": true
}
],
"expect": [
{
"name": "status",
"type": "text",
"label": "Status",
"required": true
},
{
"name": "select",
"type": "select",
"label": "Upload",
"validate": {
"enum": [
"image",
"video"
]
}
},
{
"name": "possibly_sensitive",
"type": "boolean",
"label": "Attached images contain sensitive content (nudity, violence, etc).",
"required": true
},
{
"name": "lat",
"type": "number",
"label": "Geographic Latitude",
"validate": {
"max": 90,
"min": -90
}
},
{
"name": "long",
"type": "number",
"label": "Geographic Longitude",
"validate": {
"max": 180,
"min": -180
}
},
{
"name": "display_coordinates",
"type": "boolean",
"label": "Display tweets coordinates",
"required": true
},
{
"name": "attachments",
"spec": [
{
"name": "filename",
"type": "filename",
"label": "File Name",
"semantic": "file:name"
},
{
"name": "data",
"type": "buffer",
"label": "Data",
"semantic": "file:data"
},
{
"name": "media_category",
"type": "select",
"label": "Media Category",
"options": [
{
"label": "Tweet Gif",
"value": "tweet_gif"
},
{
"label": "Tweet Image",
"value": "tweet_image"
}
]
}
],
"type": "array",
"label": "Attachments",
"validate": {
"maxItems": 4
}
}
]
}
}
]
}
]
}
],
"metadata": {
"version": 1,
"scenario": {
"roundtrips": 1,
"shatter": false,
"maxErrors": 3,
"autoCommit": false,
"sequential": false,
"confidential": false,
"dataloss": false,
"dlq": false
},
"designer": {
"orphans": []
},
"zone": "eu1.integromat.com"
}
}
以上です。では。

0 件のコメント:

コメントを投稿