Giter Club home page Giter Club logo

Comments (8)

ihorrusinko avatar ihorrusinko commented on July 16, 2024

hey @fbessez could you provide an example of your code?

from botkit-mock.

fbessez avatar fbessez commented on July 16, 2024

Of course, just for a basic help message that returns a Rich Card / Adaptive Card
controller.hears('help', 'message_received', MiscUtls.help

MiscUtils.help = (bot, message) => { const reply = { attachments: [ { contentType: "application/vnd.microsoft.card.adaptive", content: { type: "AdaptiveCard", body: [ { type: 'TextBlock', text: 'Log Work', size: 'large', weight: 'bolder' }, { type: 'TextBlock', text: 'You can log work!', size: 'normal', weight: 'normal', separation: 'none', wrap: true }, { type: 'TextBlock', text: 'Get your time', size: 'large', weight: 'bolder' }, { type: 'TextBlock', text: 'Time.', size: 'normal', weight: 'normal', separation: 'none', wrap: true } ] } }] } bot.reply(message, reply); };

Does that help? Thank you!

from botkit-mock.

amplicity avatar amplicity commented on July 16, 2024

from botkit-mock.

fbessez avatar fbessez commented on July 16, 2024

Sweet, thank you!

from botkit-mock.

ihorrusinko avatar ihorrusinko commented on July 16, 2024

Your main entry point app.js

var Botkit = require('botkit');
var controller = Botkit.botframeworkbot({
  debug: true
});

// Create the Botkit controller, which controls all instances of the bot.
var bot = controller.spawn({
  appId: process.env.app_id,
  appPassword: process.env.app_password
});


require('./indexController')(controller);

Logic of actions (indexController.js):

var MiscUtls = {};

MiscUtls.help = (bot, message) => {
  const reply = {
    attachments: [{
      contentType: "application/vnd.microsoft.card.adaptive",
      content: {
        type: "AdaptiveCard",
        body: [{type: 'TextBlock', text: 'Log Work', size: 'large', weight: 'bolder'}, {
          type: 'TextBlock',
          text: 'You can log work!',
          size: 'normal',
          weight: 'normal',
          separation: 'none',
          wrap: true
        }, {type: 'TextBlock', text: 'Get your time', size: 'large', weight: 'bolder'}, {
          type: 'TextBlock',
          text: 'Time.',
          size: 'normal',
          weight: 'normal',
          separation: 'none',
          wrap: true
        }]
      }
    }]
  };
  bot.reply(message, reply);
};

module.exports = function (controller) {
  controller.hears('help', 'message_received', MiscUtls.help)
};

tests:

'use strict';
const assert = require('assert');
const Botmock = require('botkit-mock');
const fileBeingTested = require("./indexController");

describe("controller tests", () => {
  afterEach(() => {
    //clean up botkit tick interval
    this.controller.shutdown()
  });
  
  beforeEach(() => {
    this.userInfo = {
      slackId: 'user123',
      channel: 'channel123',
    };
    
    this.controller = Botmock({
      debug: false,
    });
    
    this.bot = this.controller.spawn({});
    
    fileBeingTested(this.controller);
  });
  
  it('should return correct attachments object in message', () => {
    let sequence = [
      {
        //type: null, //if type null, default to direct_message
        user: this.userInfo.slackId, //user required for each direct message
        channel: this.userInfo.channel, // user channel required for direct message
        messages: [
          {
            text: 'help',
            isAssertion: true,
          }
        ]
      }
    ];
    
    return this.bot.usersInput(sequence).then((message) => {
      let testValue = {
        attachments: [{
          contentType: "application/vnd.microsoft.card.adaptive",
          content: {
            type: "AdaptiveCard",
            body: [{type: 'TextBlock', text: 'Log Work', size: 'large', weight: 'bolder'}, {
              type: 'TextBlock',
              text: 'You can log work!',
              size: 'normal',
              weight: 'normal',
              separation: 'none',
              wrap: true
            }, {type: 'TextBlock', text: 'Get your time', size: 'large', weight: 'bolder'}, {
              type: 'TextBlock',
              text: 'Time.',
              size: 'normal',
              weight: 'normal',
              separation: 'none',
              wrap: true
            }]
          }
        }]
      };
      return assert.deepEqual(message.attachments, testValue.attachments);
    })
  });
});

from botkit-mock.

fbessez avatar fbessez commented on July 16, 2024

@ihorrusinko @amplicity Beautiful! I really appreciate all of the work you have put in! I will double check to see if this works upon returning to work :)

from botkit-mock.

fbessez avatar fbessez commented on July 16, 2024

Great! It works wonderfully! Do you mind also mapping out for me how I'd go about testing a conversation? So if user says 'What is my name?' then bot should respond 'fbessez, right?' and then I would say 'yes' or 'no'. How do I test that out? Do I add those messages to the sequence? and then add responses?

from botkit-mock.

ihorrusinko avatar ihorrusinko commented on July 16, 2024

@fbessez checkout this example please
https://github.com/gratifyguy/botkit-mock/tree/master/examples/convo-bot
it should be what you need

from botkit-mock.

Related Issues (20)

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.