Microsoft Teams Chat Message Post
Posts a Message to Microsoft Teams Chat
Configs
  • A: OAuth 2.0 Setting *
  • B: Chat id *#{EL}
  • C: Title
  • D: Message *
  • O: Message Id (update)
  • X: Access Log (update)
Script (click to open)


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

//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2 = configs.get( "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 ){
const jsonObj = JSON.parse( response.getResponseAsString() );
let messageId = jsonObj.id + "";
if( dataId_messageId !== "" ){
engine.setDataByNumber( dataId_messageId, messageId );
}
}

if( status >= 300 ){
engine.log(accessLog);
throw `Failed in POST request. status: ${status}`;
}
if( dataId_log !== "" ){
engine.setDataByNumber( dataId_log, accessLog );
}

Download

2022-08-25 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/microsoftteams-chat-message-post/
The Addon-import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

Capture

Appendix

You can embed a hyperlink to the process detail page by entering the following in ” Update Data” in preparation for the body of the submission message.
Link to Process

See also

%d bloggers like this: