1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

kintone から Teams への通知投稿

Last updated at Posted at 2023-12-24

Kintone から Teams への通知投稿の手順

やること

kintoneから新規データが作られたときに、特定のチャネルのTeamsに通知を送る

手順

  1. 特定のイベントにフックしてTeamsに通知を飛ばす(ここでは保存成功時)

    • Kintoneで新しいデータが作られたら、その情報をTeamsに通知する処理を書く
    (function() {
     "use strict";
    
     // kintoneのレコード保存時のイベントをトリガーに設定
     const EVENTS = ['app.record.create.submit.success', 'app.record.edit.submit.success'];
     kintone.events.on(EVENTS, function(event) {
         
         // Teamsへの投稿処理を実行
         postToTeams(event.record);
    
         // イベント処理を続行
         return event;
     });
    
     // Teamsへの投稿処理
     function postToTeams(record) {
         const webhookUrl = 'https://outlook.office.com/webhook/...'; // ここにWebhook URLを設定
         const payload = {
             "@type": "MessageCard",
             "@context": "http://schema.org/extensions",
             "summary": "kintoneからの通知",
             "sections": [{
                 "activityTitle": "新しいレコードが追加/更新されました",
                 "facts": [
                     { "name": "レコード番号", "value": record['$id'].value },
                     // 他のフィールド情報をここに追加
                 ],
                 "markdown": true
             }]
         };
    
         kintone.proxy(webhookUrl, 'POST', {'Content-Type': 'application/json'}, JSON.stringify(payload), function(body, status, headers) {
             console.log('Teamsへの投稿に成功しました。', body, status);
         }, function(error) {
             console.error('Teamsへの投稿に失敗しました。', error);
         });
     }
     })();
    
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?