次の方法で共有

Teams Bot で Bot Framework Connector API の継続的な401認証エラー

大野 亮輔 0 評価のポイント
2025-09-01T08:48:17.4233333+00:00

Microsoft Teams Bot の開発で、Bot Framework Connector APIを通じてメッセージを送信しようとすると、継続的に401認証エラーが発生します。

環境:

  • Bot Framework SDK: 4.23.3 (Node.js)
  • エラー: "Authorization has been denied for this request"

正常に動作する部分:

  • Teams からのメッセージ受信(ボットはメッセージを受け取れる)
  • Bot Framework Emulator でのローカルテスト(認証なし)
  • ボットコード自体の動作確認済み

動作しない部分:

  • Teams でのボット応答(401エラー)
  • Azure Bot Service の「Web チャットでテスト」(同様の401エラー)

実施済みの対処法:

  • App Registrationの認証方法をマルチテナントに設定

エラー詳細:

RestError: Authorization has been denied for this request.
{
    "statusCode": 401,
    "details": {"message": "Authorization has been denied for this request."},
    "request": {
        "url": "https://smba.trafficmanager.net/jp/.../v3/conversations/..
    ./activities",
        "method": "POST"
    }
}

ソースコード:

const restify = require('restify');
const { BotFrameworkAdapter, ActivityHandler, MessageFactory } = require('botbuilder');
require('dotenv').config();

const server = restify.createServer();
server.use(restify.plugins.bodyParser());

const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

adapter.onTurnError = async (context, error) => {
    console.error(`\n [onTurnError] unhandled error: ${ error }`);
    console.error(error);
    await context.sendActivity('Sorry, it looks like something went wrong.');
};

class EchoBot extends ActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context, next) => {
            const replyText = `Echo: ${ context.activity.text }`;
            await context.sendActivity(MessageFactory.text(replyText, replyText));
            await next();
        });

        this.onMembersAdded(async (context, next) => {
            const membersAdded = context.activity.membersAdded;
            const welcomeText = 'Hello and welcome!';
            for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
                if (membersAdded[cnt].id !== context.activity.recipient.id) {
                    await context.sendActivity(MessageFactory.text(welcomeText, welcomeText));
                }
            }
            await next();
        });
    }
}

const myBot = new EchoBot();

server.post('/api/messages', async (req, res) => {
    await adapter.process(req, res, (context) => myBot.run(context));
});

const port = process.env.Port || 3978;
server.listen(port, () => {
    console.log(`\n${ server.name } listening to ${ server.url }`);
    console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
    console.log('\nTo test your bot, see: https://aka.ms/debug-with-emulator');
});

質問:

この Bot Framework Connector API の認証問題を解決するために、追加で必要な設定や対処法はありますか?


<モデレーター注>
本スレッドは、スパムフィルターの誤認識により削除されていましたがスレッドを復元しました。
又、同様に削除されたスレッドには重複マークを付与しました。
本スレッドにて、質問を継続してください。

Microsoft Teams
Microsoft Teams

チャット、ビデオ会議、ファイル共有、アプリ統合を統合したコラボレーションおよびコミュニケーション プラットフォームにより、チームはどこからでもリアルタイムで効果的に共同作業を行うことができます。


お客様の回答

質問作成者は回答に "承認済み"、モデレーターは "おすすめ" とマークできます。これにより、ユーザーは作成者の問題が回答によって解決したことを把握できます。