Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When will be other features like PDF Attachment, Dropdown, etc. will be added in Rasa Chatbot Widget 2.0 #28

Open
guptaji007 opened this issue Jun 21, 2023 · 0 comments

Comments

@guptaji007
Copy link

guptaji007 commented Jun 21, 2023

Features like like PDF Attachment, Dropdown, etc. will be added in Rasa Chatbot Widget 2.0 which is already present inside Chat Widget 1.0. And Inside Chatbot Widget 1.0 after pdf is render in chatbot the buttons is not showing.

actions.py

class ActionGetCertificate(Action):
    def name(self) -> Text:
        return "action_get_certificate"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        # Extract the application_number from the user input
        application_number = next(tracker.get_latest_entity_values("application_number"), None)
        if application_number:
            if len(application_number) == 12 or len(application_number) == 13:
                certificate_data = self.get_certificate(application_number)
                if certificate_data:
                    # Convert byte array into PDF
                    pdf_data = io.BytesIO(certificate_data)
                
                    # Save the PDF file into a folder
                    folder_path = "ui/static/pdf/"  # Set the path to the folder
                    file_name = f"{application_number}.pdf"  # Set the desired file name
                    file_path = os.path.join(folder_path, file_name)

                    with open(file_path, "wb") as wfile:
                        wfile.write(pdf_data.getvalue())
                    
                    # Pdf URL
                    pdf_url = f'static/pdf/{application_number}.pdf'

                    data = {
                        "payload": "pdf_attachment",
                        "title": application_number,  # Set the title as the application number
                        "url": pdf_url,  # Set the url as the pdf_data object
                    }
                    dispatcher.utter_message(text="Here is your pdf", json_message=data)
                else:
                    dispatcher.utter_message(text="Invalid application number. Please try again.")
            else:
                dispatcher.utter_message(text="The application number should be exactly 12 or 13 characters long.")
        else:
            dispatcher.utter_message(text="I'm sorry, I didn't get the application number. Please try again.")
        return []
    
    def get_certificate(self, application_number: str) -> bytes:
        wsdl_url = "http://localhost:42512/test?WSDL"  # Replace with your web service WSDL URL
        client = Client(wsdl_url)
        response = client.service.GetCertificate(ApplicationNo=application_number)
        return response

stories.yml

  • story: application_status
    steps:

    • intent: greet
    • action: utter_greet
    • intent: ask_for_application_details
    • action: utter_ask_for_application_no
    • intent: provide_application_number
      entities:
      • application_number
    • action: action_get_certificate
    • action: utter_yes_no
  • story: Greet and continue if user selects "yes"
    steps:

    • action: utter_yes_no
    • intent: affirm
    • action: utter_greet
  • story: Greet and say goodbye if user selects "no"
    steps:

    • action: utter_yes_no
    • intent: deny
    • action: utter_goodbye

domain.yml

intents:

  • greet
  • goodbye
  • affirm
  • deny
  • mood_great
  • mood_unhappy
  • bot_challenge
  • ask_for_application_details
  • provide_application_number

entities:

  • application_number

actions:

  • action_get_certificate

responses:
utter_greet:

  • text: "Hey! How can I assist you today?"

utter_yes_no:

  • text: "Do you want to continue?"
    buttons:
    • title: Yes
      payload: /affirm
    • title: No
      payload: /deny

utter_ask_for_application_no:

  • text: "Please provide your application number"

utter_cheer_up:

  • text: "Here is something to cheer you up:"
    image: "static/cub.jpg"

utter_did_that_help:

  • text: "Did that help you?"

utter_happy:

  • text: "Great, carry on!"

utter_goodbye:

  • text: "Bye"

utter_iamabot:

  • text: "I am a bot, powered by Rasa."

session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant