Sending Image through GupShup

773 Views Asked by At

Trying to send an image through GupShup. I'm using their sandbox. My backend is node.js with feathersjs. But it's returning me this error:

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: true,
      _transformState: [Object],
      [Symbol(kCapture)]: false
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'https://api.gupshup.io/sm/api/v1/msg',
    status: 400,
    statusText: 'Bad Request',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

This is the code to send the image

const form = new URLSearchParams();
  form.append('channel', 'whatsapp');
  form.append('destination', destination);
  form.append('source', app.get('GUPSHUP_NUMBER'));
  form.append('message.payload', JSON.stringify(message));
  form.append('src.name', 'OneAccess');
  console.log(form);
  try {
    const res = await fetch('https://api.gupshup.io/sm/api/v1/msg', {
      method: 'POST',
      body: form,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        apikey: app.get('GUPSHUP_API'),
      },
    });

    console.log('result message', res);
  } catch (err) {
    console.log('errro sending msg', err);
  }

This is the message that I'm trying to send

message: {
        type: 'image',
        originalUrl:
          'https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg',
        previewUrl:
          'https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg',
        caption: 'Sample image',
      },

Can anyone help me?

1

There are 1 best solutions below

0
On

Change message.payload to message. You can check the correct signature at https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation#SendImage