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

commented Jul 11, 2019

…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 433f420 to 642f220 Jul 11, 2019

@tonyanziano tonyanziano force-pushed the toanzian/#1666-attachment branch from 642f220 to 56f70fe Jul 11, 2019

@cwhitten cwhitten merged commit d3f264c into master Jul 12, 2019

2 checks passed

Emulator-CI-PR #70272 succeeded
Details
license/cla All CLA requirements met.
Details

@cwhitten cwhitten deleted the toanzian/#1666-attachment branch Jul 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.