microsoft / BotFramework-Hubot

Hubot adapter for botframework
MIT License
111 stars 40 forks source link

Can you please provide a sample #30

Closed angegar closed 6 years ago

angegar commented 6 years ago

Hi, I am completly noob in bot and i am struggling to make it works. Can you please add a basic sample in your documentation.

My understanding is that we just need to create a hubot script as documented by hubot containing an endpoint (/api/messages) which will handle the communication with botframework. Thus if i create a bot with the following code :

robot.router.post('/api/messages', function(req,resp){ data = req.body resp.send(data) }

it should work. however in using the test feature in dev.botframework.com i can't send any messages to my bot.

Any help will be great.

++

leonardochaia commented 6 years ago

I'm really new to bots too. These are more or less the steps I took to make this work using Docker:

  1. Get an ngrok account. I use this to expose hubot running on my local machine to the internet.
  2. Clone CenterForOpenScience/hubot. This has a Docker Image for Hubot.
  3. Use the wernight/ngrok image as ngrock client.
  4. Use this docker-compose.yml as a starting point, replace where appropriate.
version: '3'

volumes:
  redis_data_vol:
    external: false

services:

  redis:
    image: redis:alpine
    volumes:
      - redis_data_vol:/data
    stdin_open: true
    networks:
      overlay:
        aliases:
          - redis

  hubot:
    build:
      context: ./
    depends_on:
      - redis
    volumes:
      - ./scripts:/code/scripts
    ports:
      - 8080:8080
    stdin_open: true
    networks:
      overlay:
        aliases:
          - hubot
    environment:
      HUBOT_LOG_LEVEL: debug
      HUBOT_ADAPTER: botframework
      BOTBUILDER_APP_ID: <<REPLACE_ME>>
      BOTBUILDER_APP_PASSWORD: <<REPLACE_ME>>
      REDIS_URL: redis://redis:6379/hubot
      REDISTOGO_URL: redis://redis:6379

  ngrok:
    # depends_on:
    #   - hubot
    image: wernight/ngrok
    ports:
      - 4040:4040
    networks:
      overlay:
    environment:
      NGROK_PORT: hubot:8080
      NGROK_AUTH: <<REPLACE_ME>>

networks:
  overlay:
    driver: bridge
  1. Replace the ngrok environments with your keys.

  2. Run ngrok detached (if you restart the ngrok container, your URL will change)

    docker-compose up -d ngrok
  3. If ngrok has run successfully, go to your ngrok dashboard and copy the HTTPS URL.

  4. Log-in to Azure and create a new Bot Service (Bot Channels Registration). on the Messaging Endpoint use the URL you copied plus api/messages. It should look like this: https://foobar.ngrok.io/api/messages

  5. From Azure you should be redirected to register a Microsoft Application, there you'll get the BOTBUILDER_APP_ID and BOTBUILDER_APP_PASSWORD. Replace those on the docker-compose.

  6. Run hubot using docker-compose up hubot, you can test it from within Azure using the Test in Web Chat option of your Bot Service.

Hope this helps to get you started.

angegar commented 6 years ago

@leonardochaia thank you for your answer, i will see if i can reuse some piece. For now i think my issue is more related with my nginx ingress controller than with the way i configure hubot.

MatSFT commented 6 years ago

@angegar you can also use the yeoman generator to build a sample with hubot. For adapter specify 'botframework'

The hubot docs have more info on this https://hubot.github.com/docs/

angegar commented 6 years ago

Thank you i finally managed to make it works, i believed that i have to implement the api/messages endpoint when it is made by the adapter. :)