@meltwater/conversations-api-services 1.1.14 → 1.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,16 +23,20 @@ async function requestApi(apiUrl, accessToken, text, data) {
23
23
  let logger = arguments.length > 6 ? arguments[6] : undefined;
24
24
  let response = {};
25
25
  try {
26
- let queryStringArgs = {
26
+ let queryStringArgs = accessToken ? {
27
27
  access_token: accessToken
28
- };
29
- if (adCampaign) {
28
+ } : undefined;
29
+ if (adCampaign?.adAccountId) {
30
30
  queryStringArgs.ad_id = adCampaign.adAccountId;
31
31
  }
32
32
  if (text) {
33
33
  queryStringArgs[discussionType === 'dm' ? 'text' : 'message'] = text;
34
34
  }
35
- response = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
35
+ if (queryStringArgs) {
36
+ response = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
37
+ } else {
38
+ response = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').send(data);
39
+ }
36
40
  } catch (err) {
37
41
  if (err && err.response && err.response.body && err.response.body.error) {
38
42
  (0, _loggerHelpers.loggerError)(logger, `Failed to call instagram api: ${err.response.body.error.message}`);
@@ -229,7 +233,7 @@ async function replyHelper(accessToken, payload, logger) {
229
233
  return response.body;
230
234
  }
231
235
  async function privateMessage(accessToken, profileId, text, logger) {
232
- const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages`, accessToken,
236
+ const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`, undefined,
233
237
  // this sends in query string leaving out :shrug:
234
238
  undefined, {
235
239
  recipient: {
@@ -8,16 +8,20 @@ async function requestApi(apiUrl, accessToken, text, data) {
8
8
  let logger = arguments.length > 6 ? arguments[6] : undefined;
9
9
  let response = {};
10
10
  try {
11
- let queryStringArgs = {
11
+ let queryStringArgs = accessToken ? {
12
12
  access_token: accessToken
13
- };
14
- if (adCampaign) {
13
+ } : undefined;
14
+ if (adCampaign?.adAccountId) {
15
15
  queryStringArgs.ad_id = adCampaign.adAccountId;
16
16
  }
17
17
  if (text) {
18
18
  queryStringArgs[discussionType === 'dm' ? 'text' : 'message'] = text;
19
19
  }
20
- response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
20
+ if (queryStringArgs) {
21
+ response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
22
+ } else {
23
+ response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').send(data);
24
+ }
21
25
  } catch (err) {
22
26
  if (err && err.response && err.response.body && err.response.body.error) {
23
27
  loggerError(logger, `Failed to call instagram api: ${err.response.body.error.message}`);
@@ -214,7 +218,7 @@ async function replyHelper(accessToken, payload, logger) {
214
218
  return response.body;
215
219
  }
216
220
  export async function privateMessage(accessToken, profileId, text, logger) {
217
- const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages`, accessToken,
221
+ const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`, undefined,
218
222
  // this sends in query string leaving out :shrug:
219
223
  undefined, {
220
224
  recipient: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "description": "Repository to contain all conversations api services shared across our services",
5
5
  "main": "dist/cjs/data-access/index.js",
6
6
  "module": "dist/esm/data-access/index.js",
@@ -18,8 +18,8 @@ async function requestApi(
18
18
  let response = {};
19
19
 
20
20
  try {
21
- let queryStringArgs = { access_token: accessToken };
22
- if (adCampaign) {
21
+ let queryStringArgs =accessToken? { access_token: accessToken } : undefined;
22
+ if (adCampaign?.adAccountId) {
23
23
  queryStringArgs.ad_id = adCampaign.adAccountId;
24
24
  }
25
25
  if (text) {
@@ -27,13 +27,20 @@ async function requestApi(
27
27
  discussionType === 'dm' ? 'text' : 'message'
28
28
  ] = text;
29
29
  }
30
-
31
- response = await superagent
32
- .post(apiUrl)
33
- .set('Accept', 'application/json')
34
- .set('Content-Type', 'application/json')
35
- .query(queryStringArgs)
36
- .send(data);
30
+ if(queryStringArgs){
31
+ response = await superagent
32
+ .post(apiUrl)
33
+ .set('Accept', 'application/json')
34
+ .set('Content-Type', 'application/json')
35
+ .query(queryStringArgs)
36
+ .send(data);
37
+ }else{
38
+ response = await superagent
39
+ .post(apiUrl)
40
+ .set('Accept', 'application/json')
41
+ .set('Content-Type', 'application/json')
42
+ .send(data);
43
+ }
37
44
  } catch (err) {
38
45
  if (
39
46
  err &&
@@ -385,8 +392,8 @@ async function replyHelper(accessToken, payload, logger) {
385
392
 
386
393
  export async function privateMessage(accessToken, profileId, text, logger) {
387
394
  const response = await requestApi(
388
- `${INSTAGRAM_URL}/v10.0/me/messages`,
389
- accessToken,
395
+ `${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`,
396
+ undefined,
390
397
  // this sends in query string leaving out :shrug:
391
398
  undefined,
392
399
  {