Custom Channel Example for Rasa Core 0.12.3


Can someone please provide an example of custom input channel on rasa core “version”: “0.12.3”. Below is the code I am using , but getting error as

agent.handle_channels(InputChannel(5004, “/chat”, input_channel)) TypeError: object() takes no parameters

Here is my

from __future__ import print_function
from __future__ import unicode_literals

import logging

from rasa_core.channels import InputChannel
from rasa_core import utils
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
from import UserMessage
from import CollectingOutputChannel
from rasa_core.utils import EndpointConfig
from flask import Blueprint, request, jsonify

logger = logging.getLogger(__name__)

class SimpleWebBot(InputChannel):

    def blueprint(self, on_new_message):
        custom_webhook = Blueprint('custom_webhook', __name__)

        @custom_webhook.route("/", methods=['GET'])
        def health():
            return jsonify({"status": "ok"})

        @custom_webhook.route("/webhook", methods=['POST'])
        def receive():
            payload = request.json
            sender_id = payload.get("sender", None)
            text = payload.get("message", None)
            out = CollectingOutputChannel()
            on_new_message(UserMessage(text, out, sender_id))
            responses = [m for _, m in out.messages]
            return jsonify(responses)

        return custom_webhook
def run(serve_forever=True):
    interpreter = RasaNLUInterpreter("projects/default/mybotnlu")
    action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
    agent = Agent.load("projects/dialogue", interpreter=interpreter , action_endpoint=action_endpoint)
    input_channel = SimpleWebBot()
    if serve_forever:
      agent.handle_channels(InputChannel(5004, "/chat", input_channel))
    return agent

if __name__ == '__main__':

hey @stacybot123 let me suggest you how to connect your rasa bot with custom channel :

  1. Create credentials.yml and add the contents to the file as mentioned here : Chat & Voice platforms

  2. run your rasa core server using the below command :

python -m -d models/dialogue -u models/nlu/current --port 5002 --credentials credentials.yml

3.then you can connect your bot to your custom channel using the below api :


hope it helps :sweat_smile::smiley:

@JiteshGaikwad Thanks! it worked , but as soon as I closes the terminal the command python -m -d models/dialogue -u models/nlu/current --port 5002 --credentials credentials.yml

terminates. I was trying to run the server without keep open the terminal . Is there a way/example I attach this to a flask app


Hi @JiteshGaikwad, Can you please little elaborate, because I am not getting anything in the output?

Hey, I think what you’re trying to do is keeping the process alive even after quitting the terminal? If so, check out screen, which does exactly that for you.

Hello, can you show me your credential.yml file? Thank you, @stacybot123