Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create resend.com plugin template #852

Open
wants to merge 1 commit into
base: 0.8.2-dev
Choose a base branch
from

Conversation

ryomahan
Copy link

@ryomahan ryomahan commented Dec 5, 2023

  • I hereby declare this contribution to be licenced under the MIT license

@atompie There is a resend.com plugin demo.

You can test with the plugin named Resend: Send Email, and this plugin is implemented for send email API.

Could you please review this code to see if there are any issues with the coding logic.

image

@ryomahan
Copy link
Author

ryomahan commented Dec 5, 2023

Please also let me know if there are no issues and I will continue to complete the remaining features of this plugin.

Copy link
Collaborator

@atompie atompie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick remarks. :) By and Large the code look great.

name="Sender Email Address",
required=True,
description="To include a friendly name, use the format \"Your Name <sender@domain.com>\".",
component=FormComponent(type="dotPath", props={"label": "Resend"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use dotPath for sender which is good but the params.sender are not dun through dotAccessor to get the value.

url = f"https://api.resend.com/emails"
params = {
"from": self.config.sender,
"to": self.config.to,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use dotPath for sender, to, etc which is good but the params.sender are not dun through dotAccessor to get the value.

to get the right value when the user use dotPath like profile@data.contact.emai.main do the following:

dot = self._get_dot_accessor(payload) # This gets the class that can evaluate any dot notation.

self.config.sender = dot[self.config.sender]

this will convert the dot notation if found to the actual value. If not found it will leave the value as it is. THis should be done for all dotPaths.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be also good to check if after converting the sender, to, etc. if the values are real emails.

params["html"] = self.config.message.get("content", "")
else:
params["text"] = self.config.message.get("content", "")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no content we'd rather not send anything and return a message on error port.

"id": "",
"name": ""
},
"params": {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good practive to set the default values for params:

init={
     "resource": {
            "id": "",
            "name": ""
      },
      "params": {
            "from": "",
            "to": "profile@data.contact.email.main",
            ...
          }
}

@@ -74,6 +74,14 @@ def get_resource_types() -> List[ResourceSettings]:
"password": "<password>"
}
),
ResourceSettings(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YOu could reuse the existing api_key resource then there is no need for new ResourceSetting.

this is the one:

ResourceSettings(
            id="api-key",
            name="Api Key",
            icon="hash",
            tags=["api", "key", "token", "api_key"],
            config={
                "api_key": ""
            }
        ),

It should be first on the list.

from pydantic import BaseModel


class ResendResource(BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to reuse existing model for ApiKey. It is at: tracardi.resources.api_key

resource = await resource_db.load(config.resource.id)

self.config = config.params
self.credentials: "ResendResource" = resource.credentials.get_credentials(self, output=ResendResource)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reuse: tracardi.resource.api_key instead of ResendResource.

name="Resend Resource",
required=True,
description="Select Resend Resource.",
component=FormComponent(type="resource", props={"label": "Resend Resource", "tag": "resend"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When yo reuse existing ApiKeythen set tag to: api_key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants