Microsoft Teams Chat Message Post
Posts a message to Microsoft Teams Chat using the API (Microsoft Graph REST API).
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) 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 ){
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
- MicrosoftTeams-Chat-Message-Post-202307.xml
- 2023-07-03 (C) Questetra, Inc. (MIT License)
(Installing Addon Auto-Steps are available only on the Professional edition.)
Notes
- Get Chat ID
- For Chat
Between “…conversations/” and “?ctx=chat” in the URL to open the target chat in a Web browser: https://teams.microsoft.com/_?culture=ja-jp&country=JP&lm=deeplink&lmsrc= homePageWeb&cmpid=WebSignIn#/conversations/CHATID?ctx=chat - For Teams
Between “…threadId=” and “&ctx=channel” in the URL to open the target chat in a Web browser https://teams.microsoft.com/_?culture=ja-jp&country=JP&lm=deeplink&lmsrc= homePageWeb&cmpid=WebSignIn#/conversations/Workflow?threadId=CHATID&ctx=channel
- For Chat
- “Post Title” is only available for Teams, not for Chat
- “Post Message Body” can be specified in HTML format
- Regarding the settings for integration with Microsoft365-based services
- How to register applications on Microsoft365 (Azure Active Directory) side
- How to Setup HTTP Authentication on Questetra side
- “How to Output Files from Cloud-based Workflow Questetra to OneDrive”
- “2.2: OAuth settings on the Questetra side”
※ But the scope is https://graph.microsoft.com/Chat.ReadWrite offline_access
- “2.2: OAuth settings on the Questetra side”
- “How to Output Files from Cloud-based Workflow Questetra to OneDrive”
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