Change an email message priority/importance

NN
NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron

Hi Everyone,

Would anyone know how to change priority/importance of email that is sent out from Dataiku.
Our team is using the MessageSender class to send custom emails, and we are now trying to see if there is any way we can tag certain emails with priority as High.

If anyone has done something similar or has an idea of some documentation please do guide.

Thanks

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,024 Neuron
    edited July 17

    I don't think you will be able to do this using the built-in MessageSender class as this is just a wrapper which calls a server backend API which doesn't support setting priority:

    from dataiku.core import base, flow
    import os.path as osp, os, shutil
    import json
    from dataiku.core.intercom import backend_json_call
    
    class MessageSender():
        """
        This is a handle to interact with a message sender
        """
    
        def __init__(self, channel_id, type=None, configuration={}):
            self.type = type
            self.channel_id = channel_id
            self.configuration = configuration
            self.channel = None
    
        def _repr_html_(self,):
            s = "MessageSender[   <b>%s</b>   ]" % (self.channel_id)
            return s
    
        def get_channel(self):
            if self.channel is None:
                self.channel = backend_json_call("integration-channels/get", data={
                    "id" : self.channel_id
                })
            return self.channel
    
        def send(self, message, variables={}, project_key=None, **kwargs):
            final_params = self.configuration.copy()
            final_params.update(kwargs)
            final_params['channelId'] = self.channel_id
            final_params['message'] = message
    
            if project_key is None or len(project_key) == 0:
                project_key = os.environ.get("DKU_CURRENT_PROJECT_KEY", None)
    
            data = {
                "projectKey": project_key,
                "messaging" : json.dumps({
                    "type" : self.type,
                    "configuration" : final_params,
                }),
                "variables" : json.dumps(variables)
            }
    
            return backend_json_call("scenarios/send-message/", data=data, err_msg="Failed to send message")

    You can however use the dss-plugin-sendmail, which you can customise at will or even de-pluginise into a custom Python library, and make the required changes on the send_email() function to allow for setting the priority as shown in this SO answer.

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,024 Neuron

    PS: Let me know how it goes as I may want to use the same solution. In the meantime I raised this Product Idea as well:

    https://community.dataiku.com/t5/Product-Ideas/Add-support-for-setting-priority-in-the-MessageSender-class/idi-p/40330#M1579

Setup Info
    Tags
      Help me…