How it Works¶
The limepkg have several functions to help you save a TRAML sendout.
Create/update limeobjects from traml automation events¶
From version 1.8.0 of limepkg-transactional-message-library you can create TRAML cards from the automation step Send transactional email. This is a beta feature in limepkg-transactional-message-library and you need to enable it with a feature flag for the app.
limepkg-transactional-message-library have the possibility to create traml limeobjects based on the automation step, but its not fully compatible with all traml tracking features.
If you set the config value createAutomationLimeobjects
to true in Lime admin, the limepkg will create/update the limeobject with this information::
1. Save all mergecodes that was used in the sendout so they can be used to visualise the sendout.
2. Save the template id so it can be used to visualise the sendout.
3. Attach relations on the limeobjects from the automation step (important limitation: it can´t attach relations if the automation step was triggered on a new limobject, only updated limeobjects). The logic will relate the limeobject that triggered the automation step, and all relations on that limeobject. Add all relevant relations in Lisa or via addon installer.
If you only want to use the webhook feature towards the automation sendouts, you dont need to enable this feature (createAutomationLimeobjects) in the config. You only need to enable this feature if you want to auto-relate to other limobjects and/or visualise the sendout in the webcomponent.
Requirements for this feature to work:
- You need to have the config value createAutomationLimeobjects
set to true in Lime admin.
- You need to configure limepkg-transactional-message-library towards the same limetype as this package, OR disable the creation of limeobject card in limepkg-transactional-message-library by dont have any limetype config att all in that package.
Create limeobjects in Python customizations¶
You only need to add some code where your normal traml sendout are handled in Python. The creation of the traml cards is done from a class named TramlCardCreator:
from limepkg_traml_tracking.sdk import TramlCardCreator
TramlCardCreator(app=app, uow=uow)
TramlCardCreator(app=app)
Warning
Note the difference in the UOW if you pass that along to TramlCardCreator or not
- If you create TramlCardCreator class with a UOW, TramlCardCreator will not commit that UOW, you are responsible for do a
uow.commit()
call afterwards. (TramlCardCreator will however add everything to the UOW). - If you create TramlCardCreator class without the UOW, TramlCardCreator will create a UOW for everything and it will commit it for you.
Functions that are available for you in the TramlCardCreator class:
Save Email functions:¶
- save_traml_email_sendout - The normal add method from a send_result and Email object.
- save_traml_email_sendout_error - Save a email with status error from a Email object.
- save_traml_email_manually - For manually adding a record if you don’t want to use the two others.
Save SMS functions:¶
- save_traml_sms_sendout - The normal add method from a send_result and SMS object.
- save_traml_sms_sendout_error - Save a SMS with status error from a SMS object.
- save_traml_sms_manually - For manually adding a record if you don’t want to use the two others.
Save TRAML Email¶
You can use 3 functions in TramlCardCreator: save_traml_email_sendout, save_traml_email_sendout_error and save_traml_email_manually. We will now see how the 2 first works.
Let’s say you have this code already for your sendout in a custom limeobject:
email = traml.models.Email(
recipient_email=self.properties.email.value,
recipient_name=self.properties.name.value,
from_name="Lime Technologies",
from_email="[email protected]",
subject="My subject",
merge_codes={'{{firstname}}': self.properties.firstname.value}
)
tc = traml.tramlclient.TramlClient(app=self.application)
send_result = tc.send_transactionmail_by_template_name(
email, 'my-template'
)
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_email_sendout(
send_result=send_result,
email=email,
relations={'person': self},
template_name="my-template",
)
from limepkg_traml_tracking.sdk import TramlCardCreator
Its a good practice to maybe have some error handling as well to be able to save a card with the status "Error". This is example code to also treat any error and still save a TRAML card (with the status "Error"):
try:
email = traml.models.Email(
recipient_email=self.properties.email.value,
recipient_name=self.properties.name.value,
from_name="Lime Technologies",
from_email="[email protected]",
subject="My subject",
merge_codes={'{{firstname}}': self.properties.firstname.value}
)
tc = traml.tramlclient.TramlClient(app=self.application)
send_result = tc.send_transactionmail_by_template_name(
email, 'my-template'
)
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_email_sendout(
send_result=send_result,
email=email,
relations={'person': self},
template_name="my-template",
)
except Exception as e:
try:
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_email_sendout_error(
email=email,
error_text=str(e),
relations={'person': self},
template_name="my-template"
)
except Exception as e:
logger.exception(f"Can’t save failed traml email: {e}")
Save TRAML SMS¶
You can use 3 functions in TramlCardCreator: save_traml_sms_sendout, save_traml_sms_sendout_error and save_traml_sms_manually. We will now see how the 2 first works.
Let’s say you have this code already for your sendout in a custom limeobject:
sms = traml.models.Sms(
'+4612345', self.properties.mobilephone.value
)
tc = traml.tramlclient.TramlClient(app=self.application)
send_result = tc.send_sms('My sms text', sms)
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_sms_sendout(
send_result=send_result,
sms=sms,
text='My sms text',
relations={'person': self}
)
from limepkg_traml_tracking.sdk import TramlCardCreator
Its a good practice to maybe have some error handling as well to be able to save a card with the status "Error". This is example code to also treat any error and still save a TRAML card (with the status "Error"):
try:
sms = traml.models.Sms(
'+4612345', self.properties.mobilephone.value
)
tc = traml.tramlclient.TramlClient(app=self.application)
send_result = tc.send_sms('My sms text', sms)
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_sms_sendout(
send_result=send_result,
sms=sms,
text='My sms text',
relations={'person': self}
)
except Exception as e:
try:
tcc = TramlCardCreator(app=self.application, uow=uow)
tcc.save_traml_sms_sendout_error(
sms=sms,
error_text=str(e),
relations={'person': self}
)
except Exception as e:
logger.exception(f"Can’t save failed traml sms: {e}")