Parse quick reply payload
Note: always expects postback payload to be JSON

@this  Fbbot#
@param {object} payload - messaging envelop object
@param {function} callback - invoked after type casting is done
17706
function quickReply(payload, callback)
{
  if (payload.quick_reply && typeof payload.quick_reply.payload == 'string')
  {
    // TODO: Make better parse and as a library
    payload.quick_reply.payload = JSON.parse(payload.quick_reply.payload);
  }

  callback(null, payload);
}
411092
function sendPayload(payload) {
		var builtPayload = payload.build();
		for (var i=0; i<emitters.length; i++) {
			emitters[i].input(builtPayload);
		}
	}
953068
function processInputStream(msg) {
      var tmp = msg.payload;

      if ('string' === typeof msg.payload) {
        msg.payload = JSON.parse(tmp);
      }
      if (msg.payload.action) {
        if ('start' === msg.payload.action) {
          startPacket = msg.payload;
        }
      } else {
        msg.payload = { 'action' : 'data', 'data' : tmp };
      }

      return Promise.resolve(msg.payload);
    }
1156254
function parseJSON(body, callback) {
  let r = null;
  let err = null;

  try {
    if (typeof body === 'string') {
      r = JSON.parse(body);
    } else {
      r = body;
    }
  } catch(e) {
    err = e;
  }

  return callback(err, r);
}
1305718
def _wrap_callback_parse_parameter_data(subscription, on_data, message):
    
    if message.type == message.REPLY:
        data = web_pb2.ParameterSubscriptionResponse()
        data.ParseFromString(message.reply.data)
        subscription.subscription_id = data.subscriptionId
    elif (message.type == message.DATA and
          message.data.type == yamcs_pb2.PARAMETER):
        parameter_data = ParameterData(getattr(message.data, 'parameterData'))
        #pylint: disable=protected-access
        subscription._process(parameter_data)
        if on_data:
            on_data(parameter_data)
718739
function(params, callback) {
        /**
         * Callback for QB.chat.message.list()
         * @param {Object} error - The error object
         * @param {Object} messages - The messages object.
         * @callback listMessageCallback
         * */

        this.service.ajax({
            url: Utils.getUrl(MESSAGES_API_URL),
            data: params
        }, callback);
    }
357797
function buttonPostback(payload, callback)
{
  if (typeof payload.payload != 'string')
  {
    payload.payload = JSON.stringify(payload.payload);
  }

  callback(null, payload);
}
700169
function requestJson(options, callback) {
  const proto = options.protocol === 'https:' ? https
    : options.protocol === 'http:' ? http
      : null;
  if (!proto) {
    callback(
      new Error(`Unsupported protocol "${options.protocol}" for validator URL`)
    );
    return;
  }

  const req = proto.request(options)
    .once('error', callback)
    .once('response', (res) => {
      res.on('error', callback);
      const bodyData = [];
      res.on('data', (data) => { bodyData.push(data); });
      res.on('end', () => {
        const resBody = Buffer.concat(bodyData);
        let err, resBodyObj;
        try {
          resBodyObj = JSON.parse(resBody.toString());
        } catch (errJson) {
          err = new SyntaxError(
            `Error parsing server response as JSON: ${errJson.message}`
          );
        }

        if (res.statusCode >= 300) {
          let errMessage = `HTTP ${res.statusCode}`;
          if (res.statusMessage) {
            errMessage += `: ${res.statusMessage}`;
          }
          err = new Error(errMessage);
        }

        if (err) {
          err.statusCode = res.statusCode;
          err.statusMessage = res.statusMessage;
          err.headers = res.headers;
          err.trailers = res.trailers;
          err.body = resBodyObj !== undefined ? resBodyObj : resBody;
          callback(err);
        } else {
          callback(null, resBodyObj);
        }
      });
    });

  const {body} = options;
  if (typeof body === 'string' || Buffer.isBuffer(body)) {
    req.end(body);
  } else {
    body.on('error', (err) => {
      req.abort();
      callback(err);
    });
    body.pipe(req);
  }
}
303116
function handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, callbacks){
	var subject = json.subject;
	var body = json.body;
	if (!subject || typeof body == "undefined")
		return callbacks.ifError("no subject or body");
	//if (bIndirectCorrespondent && ["cancel_new_wallet", "my_xpubkey", "new_wallet_address"].indexOf(subject) === -1)
	//    return callbacks.ifError("you're indirect correspondent, cannot trust "+subject+" from you");
	var from_address = objectHash.getDeviceAddress(device_pubkey);
	
	switch (subject){
		case "pairing":
			device.handlePairingMessage(json, device_pubkey, callbacks);
			break;
		
		case "text":
			message_counter++;
			if (!ValidationUtils.isNonemptyString(body))
				return callbacks.ifError("text body must be string");
			// the wallet should have an event handler that displays the text to the user
			eventBus.emit("text", from_address, body, message_counter);
			callbacks.ifOk();
			break;

		case "object":
			message_counter++;
			if(typeof body !== 'object')
				return callbacks.ifError("body must be object");

			eventBus.emit("object", from_address, body, message_counter);
			callbacks.ifOk();
			break;

		case "removed_paired_device":
		//	if(conf.bIgnoreUnpairRequests) {
		//		// unpairing is ignored
		//		callbacks.ifError("removed_paired_device ignored: "+from_address);
		//	} else {
				determineIfDeviceCanBeRemoved(from_address, function(bRemovable){
					if (!bRemovable)
						return callbacks.ifError("device "+from_address+" is not removable");
					if (conf.bIgnoreUnpairRequests){
						db.query("UPDATE correspondent_devices SET is_blackhole=1 WHERE device_address=?", [from_address]);
						return callbacks.ifOk();
					}
					device.removeCorrespondentDevice(from_address, function(){
						eventBus.emit("removed_paired_device", from_address);
						callbacks.ifOk();
					});
				});
		//	}
			break;

		case "chat_recording_pref":
			message_counter++;
			eventBus.emit("chat_recording_pref", from_address, body, message_counter);
			callbacks.ifOk();
			break;
		
		case "create_new_wallet":
			// {wallet: "base64", wallet_definition_template: [...]}
			walletDefinedByKeys.handleOfferToCreateNewWallet(body, from_address, callbacks);
			break;
		
		case "cancel_new_wallet":
			// {wallet: "base64"}
			if (!ValidationUtils.isNonemptyString(body.wallet))
				return callbacks.ifError("no wallet");
			walletDefinedByKeys.deleteWallet(body.wallet, from_address, callbacks.ifOk);
			break;
		
		case "my_xpubkey": // allowed from non-correspondents
			// {wallet: "base64", my_xpubkey: "base58"}
			if (!ValidationUtils.isNonemptyString(body.wallet))
				return callbacks.ifError("no wallet");
			if (!ValidationUtils.isNonemptyString(body.my_xpubkey))
				return callbacks.ifError("no my_xpubkey");
			if (body.my_xpubkey.length > 112)
				return callbacks.ifError("my_xpubkey too long");
			walletDefinedByKeys.addDeviceXPubKey(body.wallet, from_address, body.my_xpubkey, callbacks.ifOk);
			break;
		
		case "wallet_fully_approved": // allowed from non-correspondents
			// {wallet: "base64"}
			if (!ValidationUtils.isNonemptyString(body.wallet))
				return callbacks.ifError("no wallet");
			walletDefinedByKeys.handleNotificationThatWalletFullyApproved(body.wallet, from_address, callbacks.ifOk);
			break;
		
		case "new_wallet_address":
			// {wallet: "base64", is_change: (0|1), address_index: 1234, address: "BASE32"}
			if (!ValidationUtils.isNonemptyString(body.wallet))
				return callbacks.ifError("no wallet");
			if (!(body.is_change === 0 || body.is_change === 1))
				return callbacks.ifError("bad is_change");
			if (!ValidationUtils.isNonnegativeInteger(body.address_index))
				return callbacks.ifError("bad address_index");
			if (!ValidationUtils.isValidAddress(body.address))
				return callbacks.ifError("no address or bad address");
			walletDefinedByKeys.addNewAddress(body.wallet, body.is_change, body.address_index, body.address, function(err){
				if (err)
					return callbacks.ifError(err);
				callbacks.ifOk();
			});
			break;
			
		case "create_new_shared_address":
			// {address_definition_template: [...]}
			if (!ValidationUtils.isArrayOfLength(body.address_definition_template, 2))
				return callbacks.ifError("no address definition template");
			walletDefinedByAddresses.validateAddressDefinitionTemplate(
				body.address_definition_template, from_address, 
				function(err, assocMemberDeviceAddressesBySigningPaths){
					if (err)
						return callbacks.ifError(err);
					// this event should trigger a confirmatin dialog, user needs to approve creation of the shared address and choose his 
					// own address that is to become a member of the shared address
					eventBus.emit("create_new_shared_address", body.address_definition_template, assocMemberDeviceAddressesBySigningPaths);
					callbacks.ifOk();
				}
			);
			break;
		
		case "approve_new_shared_address":
			// {address_definition_template_chash: "BASE32", address: "BASE32", device_addresses_by_relative_signing_paths: {...}}
			if (!ValidationUtils.isValidAddress(body.address_definition_template_chash))
				return callbacks.ifError("invalid addr def c-hash");
			if (!ValidationUtils.isValidAddress(body.address))
				return callbacks.ifError("invalid address");
			if (typeof body.device_addresses_by_relative_signing_paths !== "object" 
					|| Object.keys(body.device_addresses_by_relative_signing_paths).length === 0)
				return callbacks.ifError("invalid device_addresses_by_relative_signing_paths");
			walletDefinedByAddresses.approvePendingSharedAddress(body.address_definition_template_chash, from_address, 
				body.address, body.device_addresses_by_relative_signing_paths);
			callbacks.ifOk();
			break;
			
		case "reject_new_shared_address":
			// {address_definition_template_chash: "BASE32"}
			if (!ValidationUtils.isValidAddress(body.address_definition_template_chash))
				return callbacks.ifError("invalid addr def c-hash");
			walletDefinedByAddresses.deletePendingSharedAddress(body.address_definition_template_chash);
			callbacks.ifOk();
			break;
			
		case "new_shared_address":
			// {address: "BASE32", definition: [...], signers: {...}}
			walletDefinedByAddresses.handleNewSharedAddress(body, {
				ifError: callbacks.ifError,
				ifOk: function(){
					callbacks.ifOk();
					eventBus.emit('maybe_new_transactions');
				}
			});
			break;
			
		// request to sign a unit created on another device
		// two use cases:
		// 1. multisig: same address hosted on several devices
		// 2. multilateral signing: different addresses signing the same message, such as a (dumb) contract
		case "sign":
			// {address: "BASE32", signing_path: "r.1.2.3", unsigned_unit: {...}}
			if (!ValidationUtils.isValidAddress(body.address))
				return callbacks.ifError("no address or bad address");
			if (!ValidationUtils.isNonemptyString(body.signing_path) || body.signing_path.charAt(0) !== 'r')
				return callbacks.ifError("bad signing path");
			var objUnit = body.unsigned_unit;
			if (typeof objUnit !== "object")
				return callbacks.ifError("no unsigned unit");
			var bJsonBased = (objUnit.version !== constants.versionWithoutTimestamp);
			// replace all existing signatures with placeholders so that signing requests sent to us on different stages of signing become identical,
			// hence the hashes of such unsigned units are also identical
			objUnit.authors.forEach(function(author){
				var authentifiers = author.authentifiers;
				for (var path in authentifiers)
					authentifiers[path] = authentifiers[path].replace(/./, '-'); 
			});
			var assocPrivatePayloads = body.private_payloads;
			if ("private_payloads" in body){
				if (typeof assocPrivatePayloads !== "object" || !assocPrivatePayloads)
					return callbacks.ifError("bad private payloads");
				for (var payload_hash in assocPrivatePayloads){
					var payload = assocPrivatePayloads[payload_hash];
					var hidden_payload = _.cloneDeep(payload);
					if (payload.denomination) // indivisible asset.  In this case, payload hash is calculated based on output_hash rather than address and blinding
						hidden_payload.outputs.forEach(function(o){
							delete o.address;
							delete o.blinding;
						});
					var calculated_payload_hash = objectHash.getBase64Hash(hidden_payload, bJsonBased);
					if (payload_hash !== calculated_payload_hash)
						return callbacks.ifError("private payload hash does not match");
					if (!ValidationUtils.isNonemptyArray(objUnit.messages))
						return callbacks.ifError("no messages in unsigned unit");
					if (objUnit.messages.filter(function(objMessage){ return (objMessage.payload_hash === payload_hash); }).length !== 1)
						return callbacks.ifError("no such payload hash in the messages");
				}
			}
			if (objUnit.messages){
				var arrMessages = objUnit.messages;
				if (!Array.isArray(arrMessages))
					return callbacks.ifError("bad type of messages");
				for (var i=0; i<arrMessages.length; i++){
					if (arrMessages[i].payload === undefined)
						continue;
					var calculated_payload_hash = objectHash.getBase64Hash(arrMessages[i].payload, bJsonBased);
					if (arrMessages[i].payload_hash !== calculated_payload_hash)
						return callbacks.ifError("payload hash does not match");
				}
			}
			else if (objUnit.signed_message){
				// ok
			}
			else
				return callbacks.ifError("neither messages nor signed_message");
			// findAddress handles both types of addresses
			findAddress(body.address, body.signing_path, {
				ifError: callbacks.ifError,
				ifLocal: function(objAddress){
					// the commented check would make multilateral signing impossible
					//db.query("SELECT 1 FROM extended_pubkeys WHERE wallet=? AND device_address=?", [row.wallet, from_address], function(sender_rows){
					//    if (sender_rows.length !== 1)
					//        return callbacks.ifError("sender is not cosigner of this address");
						callbacks.ifOk();
						if (objUnit.signed_message && !ValidationUtils.hasFieldsExcept(objUnit, ["signed_message", "authors"])){
							objUnit.unit = objectHash.getBase64Hash(objUnit); // exact value doesn't matter, it just needs to be there
							return eventBus.emit("signing_request", objAddress, body.address, objUnit, assocPrivatePayloads, from_address, body.signing_path);
						}
						objUnit.unit = objectHash.getUnitHash(objUnit);
						var objJoint = {unit: objUnit, unsigned: true};
						eventBus.once("validated-"+objUnit.unit, function(bValid){
							if (!bValid){
								console.log("===== unit in signing request is invalid");
								return;
							}
							// This event should trigger a confirmation dialog.
							// If we merge coins from several addresses of the same wallet, we'll fire this event multiple times for the same unit.
							// The event handler must lock the unit before displaying a confirmation dialog, then remember user's choice and apply it to all
							// subsequent requests related to the same unit
							eventBus.emit("signing_request", objAddress, body.address, objUnit, assocPrivatePayloads, from_address, body.signing_path);
						});
						// if validation is already under way, handleOnlineJoint will quickly exit because of assocUnitsInWork.
						// as soon as the previously started validation finishes, it will trigger our event handler (as well as its own)
						network.handleOnlineJoint(ws, objJoint);
					//});
				},
				ifRemote: function(device_address){
					if (device_address === from_address){
						callbacks.ifError("looping signing request for address "+body.address+", path "+body.signing_path);
						throw Error("looping signing request for address "+body.address+", path "+body.signing_path);
					}
					var text_to_sign = objectHash.getUnitHashToSign(body.unsigned_unit).toString("base64");
					// I'm a proxy, wait for response from the actual signer and forward to the requestor
					eventBus.once("signature-"+device_address+"-"+body.address+"-"+body.signing_path+"-"+text_to_sign, function(sig){
						sendSignature(from_address, text_to_sign, sig, body.signing_path, body.address);
					});
					// forward the offer to the actual signer
					device.sendMessageToDevice(device_address, subject, body);
					callbacks.ifOk();
				},
				ifMerkle: function(bLocal){
					callbacks.ifError("there is merkle proof at signing path "+body.signing_path);
				},
				ifUnknownAddress: function(){
					callbacks.ifError("not aware of address "+body.address+" but will see if I learn about it later");
					eventBus.once("new_address-"+body.address, function(){
						// rewrite callbacks to avoid duplicate unlocking of mutex
						handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, { ifOk: function(){}, ifError: function(){} });
					});
				}
			});
			break;
		
		case "signature":
			// {signed_text: "base64 of sha256", signing_path: "r.1.2.3", signature: "base64"}
			if (!ValidationUtils.isStringOfLength(body.signed_text, constants.HASH_LENGTH)) // base64 of sha256
				return callbacks.ifError("bad signed text");
			if (!ValidationUtils.isStringOfLength(body.signature, constants.SIG_LENGTH) && body.signature !== '[refused]')
				return callbacks.ifError("bad signature length");
			if (!ValidationUtils.isNonemptyString(body.signing_path) || body.signing_path.charAt(0) !== 'r')
				return callbacks.ifError("bad signing path");
			if (!ValidationUtils.isValidAddress(body.address))
				return callbacks.ifError("bad address");
			eventBus.emit("signature-" + from_address + "-" + body.address + "-" + body.signing_path + "-" + body.signed_text, body.signature);
			callbacks.ifOk();
			break;
			
		case 'private_payments':
			handlePrivatePaymentChains(ws, body, from_address, callbacks);
			break;
			
		case 'payment_notification':
			// note that since the payments are public, an evil user might notify us about a payment sent by someone else 
			// (we'll be fooled to believe it was sent by the evil user).  It is only possible if he learns our address, e.g. if we make it public.
			// Normally, we generate a one-time address and share it in chat session with the future payer only.
			var current_message_counter = ++message_counter;
			var unit = body;
			if (!ValidationUtils.isStringOfLength(unit, constants.HASH_LENGTH))
				return callbacks.ifError("invalid unit in payment notification");
			var bEmitted = false;
			var emitPn = function(objJoint){
				if (bEmitted)
					return;
				bEmitted = true;
				emitNewPublicPaymentReceived(from_address, objJoint.unit, current_message_counter);
			};
			eventBus.once('saved_unit-'+unit, emitPn);
			storage.readJoint(db, unit, {
				ifNotFound: function(){
					console.log("received payment notification for unit "+unit+" which is not known yet, will wait for it");
					callbacks.ifOk();
				},
				ifFound: function(objJoint){
					emitPn(objJoint);
					eventBus.removeListener('saved_unit-'+unit, emitPn);
					callbacks.ifOk();
				}
			});
			break;
		
		case 'prosaic_contract_offer':
			body.peer_device_address = from_address;
			if (!body.title || !body.text || !body.creation_date)
				return callbacks.ifError("not all contract fields submitted");
			if (!ValidationUtils.isValidAddress(body.peer_address) || !ValidationUtils.isValidAddress(body.my_address))
				return callbacks.ifError("either peer_address or address is not valid in contract");
			if (body.hash !== prosaic_contract.getHash(body))
				return callbacks.ifError("wrong contract hash");
			if (!/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/.test(body.creation_date))
				return callbacks.ifError("wrong contract creation date");
			prosaic_contract.store(body);
			var chat_message = "(prosaic-contract:" + Buffer.from(JSON.stringify(body), 'utf8').toString('base64') + ")";
			eventBus.emit("text", from_address, chat_message, ++message_counter);
			callbacks.ifOk();
			break;

		case 'prosaic_contract_shared':
			if (!body.title || !body.text || !body.creation_date)
				return callbacks.ifError("not all contract fields submitted");
			if (!ValidationUtils.isValidAddress(body.peer_address) || !ValidationUtils.isValidAddress(body.my_address))
				return callbacks.ifError("either peer_address or address is not valid in contract");
			if (body.hash !== prosaic_contract.getHash(body))
				return callbacks.ifError("wrong contract hash");
			if (!/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/.test(body.creation_date))
				return callbacks.ifError("wrong contract creation date");
			db.query("SELECT 1 FROM my_addresses \n\
					JOIN wallet_signing_paths USING(wallet)\n\
					WHERE my_addresses.address=? AND wallet_signing_paths.device_address=?",[body.my_address, from_address],
				function(rows) {
					if (!rows.length)
						return callbacks.ifError("contract does not contain my address");
					prosaic_contract.store(body);
					callbacks.ifOk();
				}
			);
			break;

		case 'prosaic_contract_response':
			var validation = require('./validation.js');

			if (body.status !== "accepted" && body.status !== "declined")
				return callbacks.ifError("wrong status supplied");

			prosaic_contract.getByHash(body.hash, function(objContract){
				if (!objContract)
					return callbacks.ifError("wrong contract hash");
				if (body.status === "accepted" && !body.signed_message)
					return callbacks.ifError("response is not signed");
				var processResponse = function(objSignedMessage) {
					if (body.authors && body.authors.length) {
						if (body.authors.length !== 1)
							return callbacks.ifError("wrong number of authors received");
						var author = body.authors[0];
						if (author.definition && (author.address !== objectHash.getChash160(author.definition)))
							return callbacks.ifError("incorrect definition received");
						if (!ValidationUtils.isValidAddress(author.address) || author.address !== objContract.peer_address)
							return callbacks.ifError("incorrect author address");
						// this can happen when acceptor and offerer have same device in cosigners
						db.query('SELECT 1 FROM my_addresses WHERE address=? \n\
							UNION SELECT 1 FROM shared_addresses WHERE shared_address=?', [author.address, author.address], function(rows) {
								if (rows.length)
									return;
								db.query("INSERT "+db.getIgnore()+" INTO peer_addresses (address, device_address, signing_paths, definition) VALUES (?, ?, ?, ?)",
									[author.address, from_address, JSON.stringify(Object.keys(objSignedMessage.authors[0].authentifiers)), JSON.stringify(author.definition)],
									function(res) {
										if (res.affectedRows == 0)
											db.query("UPDATE peer_addresses SET signing_paths=?, definition=? WHERE address=?", [JSON.stringify(Object.keys(objSignedMessage.authors[0].authentifiers)), JSON.stringify(author.definition), author.address]);
									}
								);
							}
						);
					}
					if (objContract.status !== 'pending')
						return callbacks.ifError("contract is not active, current status: " + objContract.status);
					var objDateCopy = new Date(objContract.creation_date_obj);
					if (objDateCopy.setHours(objDateCopy.getHours() + objContract.ttl) < Date.now())
						return callbacks.ifError("contract already expired");
					prosaic_contract.setField(objContract.hash, "status", body.status);
					eventBus.emit("text", from_address, "contract \""+objContract.title+"\" " + body.status, ++message_counter);
					eventBus.emit("prosaic_contract_response_received" + body.hash, (body.status === "accepted"), body.authors);
					callbacks.ifOk();
				};
				if (body.signed_message) {
					var signedMessageJson = Buffer.from(body.signed_message, 'base64').toString('utf8');
					try{
						var objSignedMessage = JSON.parse(signedMessageJson);
					}
					catch(e){
						return callbacks.ifError("wrong signed message");
					}
					validation.validateSignedMessage(objSignedMessage, function(err) {
						if (err || objSignedMessage.authors[0].address !== objContract.peer_address || objSignedMessage.signed_message != objContract.title)
							return callbacks.ifError("wrong contract signature");
						processResponse(objSignedMessage);
					});
				} else
					processResponse();
			});
			break;

		case 'prosaic_contract_update':
			prosaic_contract.getByHash(body.hash, function(objContract){
				if (!objContract || objContract.peer_device_address !== from_address)
					return callbacks.ifError("wrong contract hash or not an owner");
				if (body.field == "status") {
					if (body.value !== "revoked" || objContract.status !== "pending")
							return callbacks.ifError("wrong status for contract supplied");
				} else 
				if (body.field == "unit") {
					if (objContract.status !== "accepted")
						return callbacks.ifError("contract was not accepted");
					if (objContract.unit)
							return callbacks.ifError("unit was already provided for this contract");
				} else
				if (body.field == "shared_address") {
					if (objContract.status !== "accepted")
						return callbacks.ifError("contract was not accepted");
					if (objContract.shared_address)
							return callbacks.ifError("shared_address was already provided for this contract");
						if (!ValidationUtils.isValidAddress(body.value))
							return callbacks.ifError("invalid address provided");
				} else {
					return callbacks.ifError("wrong field");
				}
				prosaic_contract.setField(objContract.hash, body.field, body.value);
				callbacks.ifOk();
			});
			break;
			
		default:
			callbacks.ifError("unknnown subject: "+subject);
	}
}
927832
function quickReply(payload, callback)
{
  if (typeof payload.payload != 'string')
  {
    payload.payload = JSON.stringify(payload.payload);
  }

  callback(null, payload);
}
149927
function pkginfo( clbk ) {
	var root,
		file;

	if ( !isFunction( clbk ) ) {
		throw new TypeError( 'invalid input argument. Must provide a callback function. Value: `' + clbk + '`.' );
	}
	root = resolve();
	file = path.join( root, 'package.json' );

	readJSON( file, onData );

	/**
	* FUNCTION: onData( error, data )
	*	Callback invoked after attempting to read an application's `package.json`.
	*
	* @private
	* @param {Error|Null} error - error object
	* @param {Object} data - JSON data
	* @returns {Void}
	*/
	function onData( error, data ) {
		if ( error ) {
			return clbk( error );
		}
		clbk( null, data );
	}
}
1197135
def onMessage(self, payload, is_binary):
        
        if not is_binary:
            payload = payload.decode('utf-8')

            logger.debug("Incoming message ({peer}) : {message}".format(
                peer=self.peer, message=payload))

            # Publish ON_RECEIVE message
            self.factory.mease.publisher.publish(
                message_type=ON_RECEIVE,
                client_id=self._client_id,
                client_storage=self.storage,
                message=payload)
387738
function updateState(data) {
  if (isObject(data)) {
    return {
      type: UpdateState,
      payload: data
    }
  } else {
    console.error('action updateState params must be a object')
  }
}
293180
function InternalCB (data) {

        // [good or bad] let's notify user application
        if (data.status != 0) callback (data);

        // it's time to move to next message
        if (data.status <= 0) {
            if (++idx < smsarray.length) {
                new SmsRequest (smsc, InternalCB, smsarray [idx]);
            } else {
                callback ({status: 0});
            }
        }
    }
927998
public void sendQuickReplyPayload(String payload) {
		MessageEnvelope envelope = new MessageEnvelope();
		QuickReply quickReply = new QuickReply("Sample", payload);

		ReceivedMessage message = new ReceivedMessage();
		message.setQuickReply(quickReply);
		envelope.setMessage(message);
		envelope.setSender(new User(facebookMockId));

		System.out.println("Sending quick reply: [" + message + "] as user : ["
				+ facebookMockId + "].");
		forward(envelope);
		System.out.println("Sent!");
	}
638698
function(msg, callback) {
    try {
      var result = JSON.parse(msg.content);

      // the message is ack'ed on success
      // second parameter is optional for logging
      callback(null, result);
    } catch(err) {

      // the message is nack'ed on error
      callback(err);
    }
  }
221037
function parser(msg, opts, cb) {
    let buffer = msg.payload;
    msg.payload = buffer.toString("ascii");
    cb(null, msg);
}