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

ValueFlows queries: Foody Zero Waste use case #26

Open
vcuculo opened this issue Jan 17, 2022 · 0 comments
Open

ValueFlows queries: Foody Zero Waste use case #26

vcuculo opened this issue Jan 17, 2022 · 0 comments

Comments

@vcuculo
Copy link

vcuculo commented Jan 17, 2022

As suggested by @adam-burns , I share the snippets of code involved in the Foody Zero Waste use case for the interaction with the ReflowOS backend both from the IoT device and the Telegram bot.

IoT device

  1. the phyisical device performs the login and stores the token
mutation {
  login(emailOrUsername: graphqlUser, password: graphqlPass) {
      token
  }
}
  1. when requested by the user, the physical device sends a new offer
mutation{
   createOffer(intent:{
      action: "transfer",
      name:"Donazione",
      receiver:"01FKNV3D8T0CBC8SYASJASRSS6",
      resourceConformsTo:"01FKQPHEY0YWK83MKCM8T5RE7Q",
      availableQuantity:{
         hasUnit:"01FKNWF5Q3013GYDC4A9CCY65R",
         hasNumericalValue: String(quantity)
      },
      note: getEloquentQuality(quality)
   }){
      intent{
         id
      }
   }
}
  1. It saves the newly created intent id in an array called offerIds
  2. and adopting a polling mechanism it starts checking whether an offer has been accepted
query{
   intent(id: offerIds[i]){
      satisfiedBy{
         resourceQuantity{
            hasNumericalValue
         }
      }
   }
}

Telegram bot

This client makes much more interactions (queries and mutations) with the backend, but all the GraphQL queries are collected in this file: queries.js and @srfsh started reviewing it here.

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

No branches or pull requests

1 participant