Giter Club home page Giter Club logo

oc-governance-bot's Introduction

oc-governance-bot

This bot runs entirely on the Internet Computer. It listens for open NNS proposals, using the IC heartbeat functionality to constantly poll the NNS governance canister. When an open proposal is found, its information is put into a text message that is then sent to the corresponding OpenChat group for that proposal's topic.

OpenChat currently isn't open source, but the team shared enough Candid information with me that I was able to get my bot to work. If you want to create your own bot, below I show what it took to get my bot going.

  1. Register the bot as a user on OpenChat
  2. Create the bot's user canister on OpenChat
  3. Join the bot to a group
  4. Test sending a message

Register the bot as a user on OpenChat

Simply call register_governance_bot_user with the correct username. You will need to modify this function with your bot's username.

Create the bot's user canister on OpenChat

Simply call create_governance_bot_user_canister. This will instruct OpenChat to register the canister of this user.

Join the bot to a group

Hopefully you have the bot user's canister id from the previous step. If not you can call get_governance_bot_user_canister_id to get it, or you can join a chat with the bot in the OpenChat UI and look at the canister id in the address bar of the browser.

Next you will call governance_bot_join_group and pass in the canister id of the group that you want to join. You should have created the group already. The canister id can be found in the address bar of the browser.

Test sending a message

You can test your bot using the send_message function. You might need to modify it to update the message id (if you have already used 0 as a message id) and the bot's username.

Running the bot

The key to running the bot is the heartbeat function. Once you push that to the IC, the heartbeat function will run every few seconds. You can read more about canister_heartbeat here: https://smartcontracts.org/docs/interface-spec/index.html#_heartbeat

The logic should be pretty easy to follow if you start at the heartbeat function. Basically every few seconds the NNS governance canister is polled to see if there are any open proposals. As long as the proposal id has not already been processed (stored locally in a map), then a message is sent to the appropriate group.

oc-governance-bot's People

Contributors

lastmjs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lazyanubis

oc-governance-bot's Issues

Improvements

  • Set the interval to something much longer, and try to query past proposals and just send the proposals that haven't been sent yet
  • Implement good retry logic to ensure that each proposal is truly sent to the OC group
  • Use channels instead of groups to stop people from commenting
  • Possibly add links to helpful areas of discussion
  • Clean up proposal ids when they are no longer needed, technically we have a very slow memory leak that will never be fixed
  • Once canisters can push to other canisters, we can get rid of the heartbeat and allow the governance canister to notify our canister (most of the cost of this canister is probably from polling the governance canister)
    • Another alternative is for the IC's heartbeat to allow registering different intervals or times
  • Order the proposal ids
  • Make the queue thing
  • Cull the saved proposals
  • Let's rock this

Convert to Azle

I think I'll give ownership of this to Demergent Labs possibly and rewrite it in TypeScript

Something seems wrong with the process proposals thing

I think it might be taking too long for the update calls to work...I think if you miss a lot of proposals, perhaps the canister is running into problems with that. It's hard to tell without any kind of canister logs

MVP

  • Get heartbeat working at a reasonable pace in production
  • Read the governance proposals and store which one's have been seen
  • If not seen, record the fact and send group message
  • Register the canister as a user in open chat
  • Create the group in open chat

Cleanup

  • Types file
  • Split up into files (I think a constants file might be good)
  • Alphabetize all types and imports
  • Use results where appropriate, get rid of unwraping
  • Split up into appropriate functions, get rid of multiple levels of execution

Inconsistent state

When the bot went low on cycles, it seemed like it was trying to process a canister_id that it had already processed, the message from the group would not be accepted.

Cycle warning

We really need a warning when cycles are getting low

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.