Microsoft Teams Chat: Message Post (API)

Microsoft Teams Chat Message Post

Microsoft Teams Chat メッセージ投稿

Post a Messaget to Microsoft Teams Chat

Auto Step icon
Configs for this Auto Step
conf_OAuth2
A: OAuth 2.0 Setting *
conf_chatId
B: Chat id *#{EL}
conf_subject
C: Title
conf_messsage
D: Message *
conf_messageId
O: Message Id (update)
conf_log
X: Access Log (update)
Script (click to open)


// Post Message Teams Chat via Microsoft Graph API v1.0 (ver. 202209)
// (c) 2026, Questetra, Inc. (the MIT License)

//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2  = configs.getObject( "conf_OAuth2" );

const chatId  = configs.get( "conf_chatId" ) + "";
let subject;
const dataId_subject = configs.get( "conf_subject" );
if ( dataId_subject !== "" ) {
  subject = engine.findDataByNumber( dataId_subject ) + "";
}
const content = engine.findDataByNumber( configs.get( "conf_messsage" ) ) + "";

const dataId_messageId = configs.get( "conf_messageId" );
const dataId_log       = configs.get( "conf_log" );


//// == 演算 / Calculating ==
let requestObj = {};
if ( subject ) {
  requestObj.subject = subject;
}
  requestObj.body = {};
  requestObj.body.contentType = "html";
  requestObj.body.content = content;

//engine.log("json:"+JSON.stringify( requestObj ));

let accessLog = "";
let uri = "https://graph.microsoft.com/v1.0/me/chats/" + chatId + "/messages";
let response = httpClient.begin()
  .authSetting( oauth2 )
  .body( JSON.stringify( requestObj ), "application/json" )
  .post( uri );
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";


//// == ワークフローデータへの代入 / Data Updating ==
var status = response.getStatusCode();

if( status >= 300 ){
  engine.log(accessLog);
  throw `Failed in POST request. status: ${status}`;
} else {
  const jsonObj = JSON.parse( response.getResponseAsString() );
  let messageId = jsonObj.id + "";
  if( dataId_messageId !== "" ){
    engine.setDataByNumber( dataId_messageId, messageId );
  }
}

if( dataId_log !== "" ){
  engine.setDataByNumber( dataId_log, accessLog );
}

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

Capture

See Also

Travel Request Process, Teams Chat Notification

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading