LoginSignup
0
2

More than 1 year has passed since last update.

TeamsにPerlからメッセージを送る

Posted at

初めて 作成してみて困ったのでまとめです。

コネクタの作成

送信したいチャネルの ・・・ を選択して、コネクタを選択します。

image.png

Incoming Webhookを選択します。

image.png

必要な設定をして作成します。

image.png

作成後、変更が必要な場合は 構成済みを選択すると出てきます。

image.png

コネクタの作成は完了です。

Perlのソース作成

test.cgi
use utf8;
use Time::Local;
use Encode qw/encode decode/;
use LWP::UserAgent;

# アドレス
my $url = 'https://'; # コネクタ作成で取得したアドレス。

#-------------------------------------------
#   送信用JSONヘッダ
#-------------------------------------------
my $poststr = '{';
$poststr = $poststr . '   "type":"message",';
$poststr = $poststr . '   "attachments":[';
$poststr = $poststr . '      {';
$poststr = $poststr . '         "contentType":"application/vnd.microsoft.card.adaptive",';
$poststr = $poststr . '         "contentUrl":null,';
$poststr = $poststr . '         "content":{';     # ここから
$poststr = $poststr . '    "type": "AdaptiveCard",';
$poststr = $poststr . '    "version": "1.2",';
$poststr = $poststr . '  "body": [';
$poststr = $poststr . '        {';
$poststr = $poststr . '            "type": "TextBlock",';
$poststr = $poststr . '            "size": "Large",';
$poststr = $poststr . '            "weight": "Bolder",';
$poststr = $poststr . '            "text": "今日の予定"';
$poststr = $poststr . '        },';
$poststr = $poststr . '    ]';
$poststr = $poststr . '}';
$poststr = $poststr . '';
$poststr = $poststr . '      }';            # ここまで
$poststr = $poststr . '   ]';
$poststr = $poststr . '}';
$poststrB = encode('UTF-8', $poststr);

my $ua = LWP::UserAgent->new;
$ua->default_header('Content-Type' => 'application/json; charset=utf-8 ');

my $res = $ua->post(
    $url,
    Content => $poststrB
);

Perlがよくわかってないので この段階に来るのにしばらくかかりました。

デザイン

デザインするのには
https://adaptivecards.io/designer/
が いいかと思います。

変更する場合、ソース中の # ここから # ここまで の中を変更する感じになります。

0
2
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
2