我会收到带有状态404的错误消息。

发布于 2025-02-08 06:22:16 字数 2466 浏览 2 评论 0原文

我的任务是将接收到的文件从第三方资源传输到机器人,然后在用户的聊天中转移到用户的聊天中,而无需用户确认,将文件保存在用户的频道中。 我正在使用Bot Builder 4来为团队创建一个机器人。我需要向用户的聊天发送附件。但是,当我尝试这样做时,我会在响应中获得404个错误。

我使用的功能

export async function getUploadedAttachment(turnContext) {
  const imageData = fs.readFileSync(path.join(__dirname, '../resources/image.png'));
  const connectorFactory = turnContext.turnState.get(turnContext.adapter.ConnectorFactoryKey);
  const connector = await connectorFactory.create(turnContext.activity.serviceUrl);
  const conversationId = turnContext.activity.conversation.id;
  const responce = connector.conversations.uploadAttachment(conversationId, {
    name: 'image.png',
    originalBase64: imageData,
    type: 'image/png'
  });

  // Retrieve baseUri from ConnectorClient for... something.
  const baseUri = connector.baseUri;
  const attachmentUri = baseUri + (baseUri.endsWith('/') ? '' : '/') + `v3/attachments/${encodeURI(response.id)}/views/original`;
  return {
    name: 'image.png',
    contentType: 'image/png',
    contentUrl: attachmentUri
  };
}

在响应中

code: undefined,
  statusCode: 404,
  request: WebResource {
    streamResponseBody: false,
    url: 'https://smba.trafficmanager.net/amer/v3/conversations/a%3A1dTMkfArgCiw6Rul0Ufyk1W4zUWY1l5VpU3wylTjckFCv03ywIqsN1pzD--fDRWupM92sb5rN6x0tl8U_gF6Z4ZwWC8n0KbcEWM5pd9GEKL7JogAp0IWnjzKWQRbxxaAQ/attachments',
    method: 'POST',
    headers: HttpHeaders { _headersMap: [Object] },
    body: '{}',
    query: undefined,
    formData: undefined,
    withCredentials: false,
    abortSignal: undefined,
    timeout: 0,
    onUploadProgress: undefined,
    onDownloadProgress: undefined,
    proxySettings: undefined,
    keepAlive: undefined,
    agentSettings: undefined,
    operationSpec: {
      httpMethod: 'POST',
      path: 'v3/conversations/{conversationId}/attachments',
      urlParameters: [Array],
      requestBody: [Object],
      responses: [Object],
      serializer: [Serializer]
    }
  },
  response: {
    body: '',
    headers: HttpHeaders { _headersMap: [Object] },
    status: 404
  },
  body: undefined
}

使用的功能我还使用了一个示例,来自 https://github.com/microsoft/botbuilder-samples/tree/main/main/samples/javascript_nodejs/15.handling-attachments

谢谢!

My task is to transfer the file received from a third-party resource to the bot, and then to the user's chat without confirmation from the user, saving the file in the user's channel.
I am using bot builder 4 to create a bot for Teams. I need to send attachments to the user's chat. But when I try to do this, I get a 404 error in response.

the function I use

export async function getUploadedAttachment(turnContext) {
  const imageData = fs.readFileSync(path.join(__dirname, '../resources/image.png'));
  const connectorFactory = turnContext.turnState.get(turnContext.adapter.ConnectorFactoryKey);
  const connector = await connectorFactory.create(turnContext.activity.serviceUrl);
  const conversationId = turnContext.activity.conversation.id;
  const responce = connector.conversations.uploadAttachment(conversationId, {
    name: 'image.png',
    originalBase64: imageData,
    type: 'image/png'
  });

  // Retrieve baseUri from ConnectorClient for... something.
  const baseUri = connector.baseUri;
  const attachmentUri = baseUri + (baseUri.endsWith('/') ? '' : '/') + `v3/attachments/${encodeURI(response.id)}/views/original`;
  return {
    name: 'image.png',
    contentType: 'image/png',
    contentUrl: attachmentUri
  };
}

What do I get in response

code: undefined,
  statusCode: 404,
  request: WebResource {
    streamResponseBody: false,
    url: 'https://smba.trafficmanager.net/amer/v3/conversations/a%3A1dTMkfArgCiw6Rul0Ufyk1W4zUWY1l5VpU3wylTjckFCv03ywIqsN1pzD--fDRWupM92sb5rN6x0tl8U_gF6Z4ZwWC8n0KbcEWM5pd9GEKL7JogAp0IWnjzKWQRbxxaAQ/attachments',
    method: 'POST',
    headers: HttpHeaders { _headersMap: [Object] },
    body: '{}',
    query: undefined,
    formData: undefined,
    withCredentials: false,
    abortSignal: undefined,
    timeout: 0,
    onUploadProgress: undefined,
    onDownloadProgress: undefined,
    proxySettings: undefined,
    keepAlive: undefined,
    agentSettings: undefined,
    operationSpec: {
      httpMethod: 'POST',
      path: 'v3/conversations/{conversationId}/attachments',
      urlParameters: [Array],
      requestBody: [Object],
      responses: [Object],
      serializer: [Serializer]
    }
  },
  response: {
    body: '',
    headers: HttpHeaders { _headersMap: [Object] },
    status: 404
  },
  body: undefined
}

I also used an example from https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/15.handling-attachments

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖伴 2025-02-15 06:22:16

在许多情况下,团队使用不同的机制与机器人框架机器人进行交互。样本15用于其他渠道。在样品存储库中,如果滚动到50左右,则会找到特定于团队的样本。

Teams uses different mechanisms for interacting with bot framework bots in many cases. Sample 15 is for other channels. In the samples repo, if you scroll down to 50 or so you will find Teams-specific samples. Sample 56 concerns file uploads in Teams, and you should start from there instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文