DAML Bots with DAZL

Hi DAMLers,
I found out this external blog post on how Knoldus implemented Bots in DAML with the DAZL python library. Good job @Nishchal_Vashisht :wave:

Multiple benefits like:
:sparkle: Add support for third-party APIs simply by creating bots that listen to external activity.
:sparkle: Works great with DABL Cloud Service.
:sparkle: Portable and adjustable as per requirements.
:sparkle: Quick response time.

The application flow of the Demo looks like this:

Here is the full article:

6 Likes

@Nishchal_Vashisht great article again :100:, next step would be to start using DAML Triggers, have you tried that?

CCing @cocreature on this one that for sure he will have great insights on how it looks using triggers.

2 Likes

Great blogpost @Nishchal_Vashisht! I took the liberty to write up a DAML Trigger version of your example to see how it compares. Very interest to hear your thoughts! Note that it does behave slightly differently (intentionally). In particular, it only archives proposals between the same parties and for the same model and it also makes sure to not try to archive proposals where queryParty and company are reversed which would fail.

module Trigger where

import DA.Action
import DA.Foldable
import DA.Next.Map (Map)
import Daml.Trigger
import Main

archiveTrigger : Trigger () = Trigger with
  initialize = \_ -> ()
  updateState = \_ _ () -> ()
  rule = archiveRule
  registeredTemplates = AllInDar
  heartbeat = None

archiveRule : Party -> ACS -> Time -> Map CommandId [Command] -> () -> TriggerA ()
archiveRule p acs _ _ _ = do
  let proposals = getContracts @CarProposal acs
  let finalAgreements = getContracts @FinalAgreement acs
  forA_ finalAgreements $ \(_cid, c) -> do
    -- Only match on agreements where we are the user
    when (c.user == p) $ do
      -- Filter out proposals for the same model between the same parties
      let redundantProposals =
            filter
              (\(_, proposal) ->
                proposal.companyName == c.company &&
                proposal.queryParty == c.user &&
                proposal.carModel == c.model)
              proposals
      forA_ redundantProposals $ \(cid, _) ->
        emitCommands [exerciseCmd cid RejectOffer] [toAnyContractId cid]

If you get a chance to try out triggers, let us know how it goes!

5 Likes

Great post @Nishchal_Vashisht!

4 Likes

Great post indeed. Need to look into myself on what these bots can do

1 Like