Legacy Dev Forum Posts

 View Only

Sign Up

Database.set attributes using MessagingService.sendMessage

  • 1.  Database.set attributes using MessagingService.sendMessage

    Posted 06-05-2025 18:39

    Darren_Sawyer | 2025-01-08 13:35:39 UTC | #1

    This is a follow on from https://developer.genesys.cloud/forum/t/messagingservice-plugin-start-web-messaging/31064/3

    If I use the "Database.set" command followed by the "MessagingService.sendMessage" command should the attributes set be written to participant data?

    What I have observed is that attributes that are set via the "Database.set" command are only written to participant data in Genesys Cloud if the customer sends a message on the chat.

    For example the attributes get set when I as the customer send "Yes" but I want the attribute to be set when the JS sends "Survey Opt In: Yes"

    The reason I these attributes set is I want to be able to make a routing decision based on the flag set. But it isn't being set when I use "sendMessage". I am missing something from the "sendMessage" command?

    Here is an example of my code:

    (function (g, e, n, es, ys) {
        g['_genesysJs'] = e;
        g[e] = g[e] || function () {
            (g[e].q = g[e].q || []).push(arguments)
        };
        g[e].t = 1 * new Date();
        g[e].c = es;
        ys = document.createElement('script'); ys.async = 1; ys.src = n; ys.charset = 'utf-8'; document.head.appendChild(ys);
    })(window, 'Genesys', 'https://apps.mypurecloud.ie/genesys-bootstrap/genesys.min.js', {
        environment: 'euw1',
        deploymentId: 'XXXXXXX-XXXXXXXXXX-XXXXXXXX-XXXXX'
    });
    // Initialise Database
    Genesys("subscribe", "Database.ready", function () {
        console.log("Database plugin is ready.")
    });
    // Listen for conversationDisconnected event to initiate re-initate the message.
    Genesys("subscribe", "MessagingService.conversationDisconnected", function ({ data }) {
        console.log(data);
    	// Set customer attribute for surveyOptIn
        Genesys("command", "Database.set", { messaging: { customAttributes: { surveyOptIn: 'true' } } },
            function (data) {
                console.log("Survey Opt In: Success");
            }, function () { console.log("Survey Opt In: Failed"); });
    	// Set participant data at this point
        Genesys("command", "MessagingService.sendMessage", {
            message: "Survey Opt In: Yes"
        },
            function () {
                /*fulfilled callback*/
            },
            function () {
                /*rejected callback*/
            }
        );
    });

    Thanks, Darren


    system | 2025-02-07 13:36:10 UTC | #2

    This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 31096