message: fix cb and json parsing for handover api calls
diff: @@ -746,20 +746,13 @@ function Facebookbot(configuration) {
  if (err) {
  facebook_botkit.log('Could not take thread control');
  } else {
  -
  - var results = null;
  - try {
  - results = JSON.parse(body);
  - } catch (err) {
  - facebook_botkit.log('ERROR in take thread control API call: Could not parse JSON', err, body);
  - }
  -
  - if (results) {
  - if (results.error) {
  - facebook_botkit.log('ERROR in take thread control API call: ', results.error.message);
  + if (body) {
  + if (body.error) {
  + facebook_botkit.log('ERROR in take thread control API call: ', body.error.message);
  + cb && cb(body.error)
  } else {
  facebook_botkit.debug('Successfully taken thread control', body);
  - cb && cb(result);
  + cb && cb(null, body);
  }
  }
  }
  @@ -773,7 +766,6 @@ function Facebookbot(configuration) {
  target_app_id: target,
  metadata: metadata
  };
  - console.log({request_body})
  request.post({
  url: 'https://' + api_host + '/v2.6/me/pass_thread_control',
  qs: {access_token: configuration.access_token},
  @@ -784,21 +776,13 @@ function Facebookbot(configuration) {
  if (err) {
  facebook_botkit.log('Could not pass thread control');
  } else {
  -
  - var results = null;
  - try {
  - results = JSON.parse(body);
  - } catch (err) {
  - facebook_botkit.log('ERROR in pass thread control API call: Could not parse JSON', err, body);
  - }
  -
  - if (results) {
  - if (results.error) {
  - facebook_botkit.log('ERROR in pass thread control API call: ', results.error.message);
  - cb && cb(results)
  + if (body) {
  + if (body.error) {
  + facebook_botkit.log('ERROR in pass thread control API call: ', body.error.message);
  + cb && cb(body)
  } else {
  facebook_botkit.debug('Successfully pass thread control', body);
  - cb && cb(null, results);
  + cb && cb(null, body);
  }
  }
  }
  