Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where uploaded attachments weren't being encoded and deco… #1678

Merged
merged 1 commit into from
Jul 12, 2019

Conversation

tonyanziano
Copy link
Contributor

…ded properly.

Fixes #1666

===

Also made sure that this did not undo any of the work done in #1661

Tested against the attachment sample -- sample 15 -- in BotBuilder-Samples, as well as against the scenario provided by the user in #1666.

===

The sample JSON file I uploaded through the Emulator:

{
  "payload": "hey :)"
}

My bot code:

onTurn() {
  return async (context) => {

    if (context.activity.attachments && context.activity.attachments.length && context.activity.attachments[0]) {
      const activity = context.activity.attachments[0];

      // json payload 
      if (activity.contentType === 'application/json') {
        const attachmentContentUrl = activity.contentUrl;
        const response = await fetch(attachmentContentUrl);
        const attachmentData = await response.json(); // { type: buffer, data: <array of bytes> }
        const readableJsonString = Buffer.from(attachmentData.data).toString();
        await context.sendActivity(`Decoded JSON payload: ${readableJsonString}`);
      }
    }
}

Running this in the Emulator:

image

@tonyanziano tonyanziano force-pushed the toanzian/#1666-attachment branch from 642f220 to 56f70fe Compare July 11, 2019 23:56
@cwhitten cwhitten merged commit d3f264c into master Jul 12, 2019
@cwhitten cwhitten deleted the toanzian/#1666-attachment branch July 12, 2019 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uploaded JSON file attachment garbled by emulator
2 participants