[Solved ✅] custom action not working
I am trying to create a custom action in gmail to create a draft reply in email thread, below is my code
@action(toolname="gmail", requires=["requests"])
def create_gmail_draft_reply(auth: dict, custom_param: dict) -> str:
"""
Create a draft reply in a Gmail thread using Gmail API.
:param auth: Dictionary containing authentication headers and base URL
:param custom_param: Dictionary with 'threadId', 'messageId', 'to', 'from', 'subject', and 'body'
:return info: String response from the Gmail API
"""
# Fetch authentication headers
headers = auth["headers"]
base_url = auth["base_url"]
# Extract custom parameters
thread_id = custom_param.get("threadId")
message_id = custom_param.get("messageId")
to_email = custom_param.get("to")
from_email = custom_param.get("from")
subject = custom_param.get("subject")
body_text = custom_param.get("body")
# Validate required parameters
if not all([thread_id, message_id, to_email, from_email, subject, body_text]):
return "Missing required parameters in custom_param"
message = MIMEText(body_text)
message['to'] = to_email
message['from'] = from_email
message['subject'] = subject
message['In-Reply-To'] = message_id
message['References'] = message_id
raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
draft_body = {
'message': {
'raw': raw_message,
'threadId': thread_id
}
}
draft_url = f"{base_url}/users/me/drafts"
response = requests.post(draft_url, headers=headers, json=draft_body)
return str(response.json())
custom_param = {
"threadId": "XX",
"messageId": "XX",
"to": "XX",
"from": "me",
"subject": "Re: Subject",
"body": "This is a reply to your email."
}
entity = composio_toolset.get_entity(id='ID')
res = entity.execute(
action=create_gmail_draft_reply,
params=custom_param
)

3 Replies
flat-fuchsia•3mo ago
hey
i will look into this error, however, i think we already have a create email draft action.
rare-sapphireOP•3mo ago
create email draft is there but creating draft in thread is not there
This hsas been resolved. The code is following