How to pass attribute from html tag to python action file?

I have created custom connector and call webhook API using jquery to pass that attribute in action file of rasa.
-> Here is my code of index.html

<html>
<body>
    <div id="rasa-chat-widget" api-key="E7paWtyYWZ0LmNvbV96QTVhOXc5UHBiQ9e" data-websocket-url="http://localhost:5005"></div>
    <script src="https://unpkg.com/@rasahq/[email protected]/dist/widget.js" type="application/javascript"></script>
</body>

<script>
    $(document).ready(function() {
            
            var api_key   = $("#rasa-chat-widget").attr('api-key');
            console.log('API KEY...',api_key);
            var attributes = {
                "get_api_key": api_key,
            };
            $.ajax({
                url: "http://localhost:5055/webhook/",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify({
                    "sender": "user",
                    "message": 'userInput',
                    "attributes": attributes
                }),
                success: function(response) {
                    console.log("Message sent successfully:", response);
                },
                error: function(error) {
                    console.error("Error sending message:", error);
                }
            });
    });
</script>

-> Here is my custom connector file code which is located on root directory of the rasa project

from rasa.core.channels.channel import InputChannel, UserMessage, OutputChannel
from sanic import Blueprint, response

class MyCustomConnector(InputChannel):
    @classmethod
    def name(cls):
        return "my_custom_connector"

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

        @custom_webhook.route("/", methods=["GET"])
        async def health(request):
            return response.json({"status": "ok"})

        @custom_webhook.route("/webhook", methods=["POST"])
        async def receive(request):
            payload = request.json
            sender_id = payload.get("sender", None)
            text = payload.get("message", None)
            attributes = payload.get("attributes", {})
            print('ATTRIBUTES....',attributes)
            out_channel = self.get_output_channel()
            if text:
            await on_new_message(
                UserMessage(text, out_channel, sender_id, input_channel=self.name(), metadata=attributes)
            )
            return response.json({"status": "message received"})

        return custom_webhook

    def get_output_channel(self) -> OutputChannel:
        return CollectingOutputChannel()

class CollectingOutputChannel(OutputChannel):
    @classmethod
    def name(cls):
        return "my_custom_connector_output"

    async def send_text_message(self, recipient_id, text, **kwargs):
        print(f"Sending message to {recipient_id}: {text}")

    
    

-> Here is my custom action code which is located on actions/action.py

# Retrieve custom attributes
        custom_attributes = tracker.latest_message.get('metadata', {})
        print('CUSTOM ATTRIBUTES...',custom_attributes)
        custom_attribute1 = custom_attributes.get("get_api_key")
        print('CUSTOM ATTRIBUTES API...',custom_attribute1)
        

-> Here is my credentails.yml file code

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered
  session_persistence: true
  my_custom_connector.MyCustomConnector:
  

-> Here is my endpoint.yml file code

action_endpoint:
  url: "http://localhost:5055/webhook"
  cors: true

This is all the code but it gives me none from custom data so what should I do ?

New contributor

pratham rajdev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật