rivescripthandlers.js
/*
   * Rivescript subroutine to handle 'subBlockUser'
   */
Rivescript subroutine to handle 'subBlockUser'
Rivescript subroutine to handle ' subBlockUser '
async subBlockUser(rs, args) {
    assert(args.length > 0);
    let userId = parseInt(args[0]);
    let dbc = await MongoClient.connect(mongoUrl, { useNewUrlParser: true });
    let db = dbc.db('demo'); 
    let colUsers = await db.collection('users');
    let user = await colUsers.findOne({ _id: userId });
    dbc.close();
    if (!user) {
      return 'User not found!'
    } else {
      return JSON.stringify({
        "blocks": [
        	{
        		"type": "section",
        		"text": {
        			"type": "mrkdwn",
        			"text": `Are you sure to block user: ${user.name}?`
        		},
        		"accessory": {
        			"type": "button",
        			"text": {
        				"type": "plain_text",
        				"text": "Confirm",
        				"emoji": true
        			},
        			"value": `${user._id}`,
              "action_id": "block_user"
        		}
        	}
        ]
      });
    }
  }
async subBlockUser ( rs , args ) { assert ( args . length > 0 ) ; let userId = parseInt ( args [ 0 ] ) ; let dbc = await MongoClient . connect ( mongoUrl , { useNewUrlParser : true } ) ; let db = dbc . db ( 'demo' ) ; let colUsers = await db . collection ( 'users' ) ; let user = await colUsers . findOne ( { _id : userId } ) ; dbc . close ( ) ; if ( ! user ) { return 'User not found!' } else { return JSON . stringify ( { "blocks" : [ { "type" : "section" , "text" : { "type" : "mrkdwn" , "text" : ` ${ user . name } ` } , "accessory" : { "type" : "button" , "text" : { "type" : "plain_text" , "text" : "Confirm" , "emoji" : true } , "value" : ` ${ user . _id } ` , "action_id" : "block_user" } } ] } ) ; } }
Rivescript subroutine to handle 'subBlockUser'
Rivescript subroutine to handle ' subBlockUser '
// Create a demo database // Return the block UI created by Slack Block Kit Builder: // https://api.slack.com/tools/block-kit-builder