How to use rest api channel in bot.py?

rasa-core

(Azizullah) #1

@alexweidauer @souvikg10

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging
import rasa_core
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils import EndpointConfig
from rasa_core.run import serve_application
from rasa_core import config
from rasa_core.tracker_store import RedisTrackerStore
from rasa_core.domain import TemplateDomain
from bot_server_channel import BotServerInputChannel


logger = logging.getLogger(__name__)

def train_dialogue(domain_file = 'domain.yml',
					model_path = './models/dialogue',
					training_data_file = './data/stories.md'):
					
	agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)])
	data = agent.load_data(training_data_file)
	agent.train(data)	
	agent.persist(model_path)
	return agent

def preprocessor(message_text):
    text = message_text.strip()
    return text

def run_weather_bot(serve_forever=True):
	interpreter = RasaNLUInterpreter('./models/nlu/Auto/Auto')
	domain = TemplateDomain.load("models/dialogue/domain.yml")
	action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
        tracker_store = RedisTrackerStore(domain,host="localhost", port=6379, db= 13)

	agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint,tracker_store=tracker_store)
        #channel = BotServerInputChannel(agent, port=5005)
         #agent.handle_channels([channel], http_port=5005)

        channel = BotServerInputChannel(agent, preprocessor=preprocessor, port=5005)
        agent.handle_channels([channel], http_port=5005)
	rasa_core.run.serve_application(agent ,channel=channel)
		
	return agent
	
if __name__ == '__main__':
	run_weather_bot()

I get the blank response

curl -X POST http://localhost:5005   -d '{"sender": "aziz", "message": "hi"}'   -H "Content-type: application/json"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>


(Naoko Reeves) #2

webhook config shows “http://localhost:5055/webhook” but looks like request url is missing “/webhook”. change the request to curl -X POST http://localhost:5005/webhook -d '{"sender": "aziz", "message": "hi"}' -H "Content-type: application/json" and see?


(Azizullah) #3

@naoko Thanks for the reply but I face the same.

curl -X POST http://localhost:5005/webhook -d '{"sender": "aziz", "message": "hi"}' -H "Content-type: application/json" and see?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>
curl: (6) Could not resolve host: and
curl: (6) Could not resolve host: see

(Souvik Ghosh) #4

it should be webhooks/rest/webhook i suppose