Hello,
Unfortunately, it is currently not possible to send an email from a Script (via a Genesys Cloud Data Action).
As you mentioned in your post, creating/sending a Genesys Cloud E-Mail requires a user context (access token obtained via Implicit Grant, Authorization Code Grant, SAML2 Bearer Grant) when invoking the corresponding Platform API endpoint.
Genesys Cloud Data Actions integration relies on an OAuth Client Credentials Grant client to authenticate and get authorized (configuration at the Genesys Cloud Data Actions integration level) - "server" context.
Which means that a request to create an email out will be rejected when invoked via a Genesys Cloud Data Action (from an Architect flow, from a Script, ...).
The Third Party Email and Chat Routing article is not about Genesys Cloud emails.
The request can indeed be used with an access/authorization token obtained via Client Credentials Grant.
But in this case, it can only create a 3rd party email - submitted to Genesys Cloud for distribution, to a Contact Center Agent, as a task/work-item of mediaType email.
It will comply with Agent utilization settings for email (in Genesys Cloud). But it is not a "real" email (no email will be sent out to a Mail Server/email address).
In future:
There is a Genesys Cloud idea on Agentless Email.
The idea is to allow sending an email out (a real email this time) using a Client Credentials Grant token - like the Agentless SMS.
The idea appears to have been accepted. But I don't have a timeline to communicate when it will be implemented and made available.
There is another idea you can vote for (in Community review) to allow Genesys Cloud Data Actions to manipulate conversations.
Now:
Currently, the only way would be for you to develop a custom web app, that leverages Platform API, and that is embedded in the Genesys Desktop.
You can run/host a web page/web app inside Genesys Cloud Desktop with Client Application integrations.
In your use case, an appropriate one could be the interaction widget integration as it will be made available as a custom tab in the conversation, and as you can pass the corresponding conversationId to your web app via URL interpolation with pcConversationId.
The code in your web app can trigger a user context based authorization flow (e.g. Token Implicit Grant). The web app running inside Genesys Desktop, this authorization process/flow will be transparent to the user (he won't have to enter his username/credentials on a login page for this).
From there, you can invoke Platform API requests on behalf of the user - which means that the request to create an email out (a real one) will be accepted. You can also retrieve the identity (username/email/displayName) of the logged-in user.
You can have a look at this Chat Assistant blueprint. It does not cover email but shows how to leverage an interaction widget exposing a web app (that leverages Platform API - using a Token Implicit Grant authorization flow).
As a note, you could possibly also expose a web app inside the Script itself (via a web component).
But depending on what identity provider is used for authentication (Genesys Cloud, Salesforce, Okta, ...), there might be cases where the user would not be automatically signed in.
I don't know for sure - but not having all these IdP available in a test environment, I haven't tried/tested the behavior for authorization flow in these different scenari and if the user is prompted to login or not.
Regards,