Skip to content
Discussions/Outreach/DAML Bots with DAZLForum ↗

DAML Bots with DAZL

Outreach5 posts1,754 views18 likesLast activity Jul 2020
AN
andreolfOP
Jul 2020

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:

Knoldus Blogs – 8 Jul 20

Implementing Bots in DAML Application

In this blog, we will explore the Bots in DAML, we will start with basic introduction about Bots than we move to why do we need it and how we can implements Bot

AN
andreolf
Jul 2020

@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.

CO
cocreature
Jul 2020

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!

NE
nemanja
Jul 2020

Great post @Nishchal_Vashisht!

BA
bartcant
Jul 2020

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

← Back to Discussions