0

Also, when i debugged it, the req.body in getting error - <Buffer 65 79 4a 30 65 58 41 69 4f 69 4a 4b 56 31 51 69 4c 43 4a 68 62 47 63 69 4f 69 4a 49 55 7a 49 31 4e 69 4a 39 2e 65 77 30 4b 49 43 41 69 61 57 35 42 63 ... >

   congig.json
{
    "workflowApiVersion": "1.1",
    "metaData": {
        "icon": "images/icon.png",
        "iconSmall": "images/iconSmall.png",
        "category": "message"
    },
    "type": "REST",
    "lang": {
        "en-US": {
            "name": "Nexmo",
          "description": "SMS.",
          "step1Label": "Nexmo"
        }
    },
    "arguments": {
        "execute": {
           "inArguments":[
             {
          "phone": "{{Contact.Attribute.DEActivity.Phone}}"
        },
        {
                  "emailAddress": "{{Contact.Attribute.DEActivity.EmailAddress}}"
                }                                       
            ],
          "outArguments": [],
          "url": "https://urltest.herokuapp.com/journeybuilder/execute",
           "verb": "POST",
            "body": "",
            "header": "",
            "format": "json",
            "useJwt": true,
            "timeout": 2000
        }
    },
    "configurationArguments": {
      "applicationExtensionKey": "xxxxxx",
      "save": {
        "url": "https://urltest.herokuapp.com/journeybuilder/save",
          "verb": "POST",
        "useJwt": true
       },
       "publish": {
        "url": "https://urltest.herokuapp.com/journeybuilder/publish",
           "verb": "POST",
        "useJwt": true
       },
      "validate": {
        "url": "https://urltest.herokuapp.com/journeybuilder/validate",
        "verb": "POST",
        "useJwt": true
      }
    },
    "wizardSteps": [
        { "label": "Configure Activity", "key": "step1" }
    ],
    "userInterfaces": {
        "configModal": {
            "height": 400,
            "width": 1000,
          "fullscreen": false
        }
    },
    "schema": {
        "arguments": {
            "execute": {
                "inArguments": [],
                "outArguments": []
            }
        }
    }
}
   index.html
<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="css/styles.css">
    <link rel="shortcut icon" href="#">
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <!--<script type="text/javascript" src="js/require.js"></script> -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
    
    <script type="text/javascript">
        (function () {
            var config = {
                baseUrl: 'js'
            };

            var dependencies = [
                'customActivity'
            ];

            require(config, dependencies);
        })();
    </script>
</head>

<body>
    <div id="step1" class="step">
        <div class="slds-grid">

            <main class="slds-col">
               
                <h1>welcome to your activity!</h1>
            </main>
            
        </div>

    </div>
</body>

</html>
   activity.js
'use strict';
var util = require('util');

// Deps
const Path = require('path');
const JWT = require(Path.join(__dirname, '..', 'lib', 'jwtDecoder.js'));
var util = require('util');
var http = require('https');
//const Nexmo = require('nexmo');
//var axios = require('axios');
//const Vonage = require('@vonage/server-sdk');
const express = require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs');
const Nexmo = require('nexmo');
//const socketio = require('socket.io');


exports.logExecuteData = [];

function logData(req) {
    exports.logExecuteData.push({
        body: req.body,
        headers: req.headers,
        trailers: req.trailers,
        method: req.method,
        url: req.url,
        params: req.params,
        query: req.query,
        route: req.route,
        cookies: req.cookies,
        ip: req.ip,
        path: req.path,
        host: req.host,
        fresh: req.fresh,
        stale: req.stale,
        protocol: req.protocol,
        secure: req.secure,
        originalUrl: req.originalUrl
    });
    console.log("body: " + util.inspect(req.body));
    console.log("headers: " + req.headers);
    console.log("trailers: " + req.trailers);
    console.log("method: " + req.method);
    console.log("url: " + req.url);
    console.log("params: " + util.inspect(req.params));
    console.log("query: " + util.inspect(req.query));
    console.log("route: " + req.route);
    console.log("cookies: " + req.cookies);
    console.log("ip: " + req.ip);
    console.log("path: " + req.path);
    console.log("host: " + req.host);
    console.log("fresh: " + req.fresh);
    console.log("stale: " + req.stale);
    console.log("protocol: " + req.protocol);
    console.log("secure: " + req.secure);
    console.log("originalUrl: " + req.originalUrl);
}

/*
 * POST Handler for / route of Activity (this is the edit route).
 */
exports.edit = function (req, res) {
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    //res.send(200, 'Edit');
    res.status(200).send('Edit');
};

/*
 * POST Handler for /save/ route of Activity.
 */
exports.save = function (req, res) {
    // Data from the req and put it in an array accessible to the main app.
    console.log( req.body );
    logData(req);
    //res.send(200, 'Save');
    res.status(200).send('Save');
};

/*
 * POST Handler for /execute/ route of Activity.
 */
exports.execute = function (req, res) {

    console.log("For Execute"); 
    
  
JWT(req.body, process.env.jwtSecret, (err, decoded) => {
  if (err) {
    console.error(err);
    return res.status(401).end();
  }
  if (decoded && decoded.inArguments && decoded.inArguments.length > 0) {
    var decodedArgs = decoded.inArguments[0];
    logData(req);
    // do something
  }else {
    console.error('inArguments invalid.');
    return res.status(400).end();
  }
});

  
    //var requestBody = req.body.inArguments[0];

    logData(req);
    res.status(200).send('Execute');

  
};


/*
 * POST Handler for /publish/ route of Activity.
 */
exports.publish = function (req, res) {
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    //res.send(200, 'Publish');
    res.status(200).send('Publish');

};

/*
 * POST Handler for /validate/ route of Activity.
 */
exports.validate = function (req, res) {
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    //res.send(200, 'Validate');
    res.status(200).send('Validate');
};
   customActivity.js
define([
    'postmonger'
], function (
    Postmonger
) {
    'use strict';

    var connection = new Postmonger.Session();
    var authTokens = {};
    //var authTokens ;
    var payload = {};
    $(window).ready(onRender);

    connection.on('initActivity', initialize);
    connection.on('requestedTokens', onGetTokens);
    connection.on('requestedEndpoints', onGetEndpoints);

    connection.on('clickedNext', save);
   
    
    function onRender() {
        // JB will respond the first time 'ready' is called with 'initActivity'
        connection.trigger('ready');

        connection.trigger('requestTokens');
        connection.trigger('requestEndpoints');

    }

    function initialize(data) {
        console.log("INITACTIVITY INITACTIVITY INITACTIVITY INITACTIVITY INITACTIVITY ");
        console.log(data);
        if (data) {
            payload = data;
        }
        
        var hasInArguments = Boolean(
            payload['arguments'] &&
            payload['arguments'].execute &&
            payload['arguments'].execute.inArguments &&
            payload['arguments'].execute.inArguments.length > 0
        );

        var inArguments = hasInArguments ? payload['arguments'].execute.inArguments : {};
        console.log("INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS ");
        console.log(inArguments);
        console.log("INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS INARGS ");

//        console.log(inArguments);

        $.each(inArguments, function (index, inArgument) {
            $.each(inArgument, function (key, val) {
                
              
            });
        });

        connection.trigger('updateButton', {
             button: 'next',
            text: 'done',
            visible: true
        });
    }

    function onGetTokens(tokens) {
        console.log("Tokens function: "+JSON.stringify(tokens));
        console.log(tokens);
        authTokens = tokens;
    }

    function onGetEndpoints(endpoints) {
        console.log("Get End Points function: "+JSON.stringify(endpoints));
        console.log(endpoints);
    }

    function save() {
        console.log("Save Save Save Save Save Save"); 

      /*  payload['arguments'].execute.inArguments = [{
            "tokens": authTokens,
            "emailAddress": "{{Contact.Attribute.DECustom.EmailAddress}}",
            "phone": "{{Contact.Attribute.DECustom.Phone}}"
        }];
        
*/

        payload['arguments'].execute.inArguments = [{
            "tokens": authTokens,
            "emailAddress": "test@test.com",
            "phone": "91XXXXXXXXXX"
           
        }];
    

        payload['metaData'].isConfigured = true;

        console.log(payload);
        console.log("payload: "+JSON.stringify(payload));
        console.log(tokens);
        

        connection.trigger('updateActivity', payload);
    }



    
});
New contributor
Kajal Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • Welcome to SFSE! Please edit to add as much detail about the problem as you can (a block of code is usually not enough) and show only the relevant code in your post. This helps the community, and you, identify the issue more effectively. – David Reed Feb 20 at 15:47
  • Please use the tools in the editor to format your post, including code blocks (the {} tool), and please include only the code needed to reproduce the problem. – David Reed Feb 22 at 4:03
  • Hey David, Thanks for the help. I have edited the code and posted it again. – Kajal Singh Feb 22 at 4:09
  • Can you update your execute method in the activity.js file to make it more clear which section is logging the data to the console. That response is a buffer and not an error code. Also, you should try logging your decodedArgs variable to the console as that's your actual payload. – Jason Hanshaw 2 days ago

Your Answer

Kajal Singh is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.