首页 > 解决方案 > 通过 GupShup 发送图像

问题描述

尝试通过 GupShup 发送图像。我正在使用他们的沙箱。我的后端是带有feathersjs 的node.js。但它返回给我这个错误:

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
  }
}

这是发送图像的代码

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);
  }

这是我要发送的信息

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',
      },

谁能帮我?

标签: javascriptnode.jsimagewhatsappgupshup

解决方案



推荐阅读