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

feat: Automation rules #3195

Closed
2 tasks done
muhsin-k opened this issue Oct 11, 2021 · 18 comments
Closed
2 tasks done

feat: Automation rules #3195

muhsin-k opened this issue Oct 11, 2021 · 18 comments
Assignees
Labels
Milestone

Comments

@muhsin-k
Copy link
Member

muhsin-k commented Oct 11, 2021

Problem

There will be tons of repeatable tasks for any team that can be automated — like assigning a specific type of conversation to the right team or adding correct labels.

Ex: Suppose an agent receives a message from a premium customer in their chatwoot dashboard. Then, an agent can add the label "priority conversation" based on their plan and prioritize them. Now this flow is carried out manually. This kind of issue can solve by adding automation rules.

Automation can replace and automate existing processes that require manual effort. You can do many things with automation, including adding labels and assigning conversation to the best agent. So the team focuses on what they do best and spends more time on manual tasks.

Automation helps,

  • The right team will always handle conversations and in the correct order.
  • Increase teams' efficiency
  • Preserve customers happiness
  • Better workload management

Solution

Automation rules consist of three parts, event, conditions, and actions. The list of defined actions will be performed sequentially when matching all the conditions after the specified event is triggered. As simple as "when, If this, then that."

Engineering Spec

Back End

Data Model

Automation

  • automation_name → The name of the automation rule
  • automation_description → Description about automation rule
  • automation_trigger_count → Number of times automation executed
  • automation_active → The automation is active or not
  • automation_event -> Events that qualify to start scanning for the automation conditions ex: Conversation is closed, Conversation is opened, Label is added, Label is removed, Assignee changes to, etc.
  • automation_conditions -> Filters for any conditions that a conversation or contact must meet for the actions to apply.
  • autmation_actions → Actions specify the actions that will result when the rule is processed successfully (when all filter conditions are met). All the actions will execute sequentially once the rule condition is met (at Atleast minimum, one action is required) ex: Send Message (Option to send a message), Update custom fields, Assign conversation, etc

Front End

  • Create a new page called "Automations" under the settings page
  • Show a button at the top of the page called "Add automation."
  • On clicking the "Add automation" button, show a modal. Add the ability to create new automation using automation_name, automation_description, automation_event, automation_conditions and autmation_actions
  • Supports pagination and filter
  • Add the ability to clone/edit/delete automation from the table

Todo

  • CRUD APIs for automation (Account level)
  • Create a new route Automations under the settings page
  • Add the option to create a new automation rule
  • Add the option to clone/edit/delete automation rule
  • List automation rules in a table
  • Background job for executing the automation

Success metrics

  • Automation rules help your team's workflows for optimum efficiency and ensure your customers get the best experience possible.
  • Automations rules save time in the long run.
  • Every customer should get the best answer as fast as possible.

Questions

  • Is the automation rule works in all inboxes?
  • Priority of rules

Frontend

@pranavrajs pranavrajs added the feature-request This label is used to track new features which is a significant change to existing product label Oct 11, 2021
@tejaswinichile
Copy link
Contributor

tejaswinichile commented Oct 12, 2021

Params structure we are getting at backend [API]

{
  automation_name: "Some Name"
  automation_description: "Some Description"
  automation_event: "Conversation Created"{dropdown}
  automation_conditions [
    {
      select attribute: BROWSER_LANGUAGE/COUNTRY/MESSAGE_CONTENT/STATUS/ASSIGNEE/TEAM
      select operator: IS/IS NOT/EQUALS TO/NOT EQUAL TO/CONTAINS/ DOES NOT CONTAINS'
      select value: en
    }
  ]
  automation_actions: [
    Send Message: { Message: value },
    Add Label: [ priority_customer ],
    Assign best agents: [ Mutiselct of agents ]
    Update Custom Attributes: [
      attribute_key: attribute_value
    ]
    Pin the conversation: /* future scope */
  ]
}

Examples

Example 1:

{
  automation_name: "Paid Plan: Conversation Automation"
  automation_description: "Silver Paid Plan, Customer Conversation Automation"
  automation_event: "Conversation Created" {dropdown}
  automation_conditions: [
    {
      automation_conditions_attribute: plan /* Custome Attribute */
      automation_conditions_operator: EQUALS TO
      automation_conditions_value: Silver
    },
    {
      automation_conditions_attribute: Country /* Custome Attribute */
      automation_conditions_operator: EQUALS TO
      automation_conditions_value: USA
    }
  ]
  automation_actions: [
    Send Message: 
      { 
        Message: 'Welcome to the chatwoot platform.' 
      },
    Assing to team : "Customer Success"
    Add Label: [ priority_customer ],
    Assign Best Agents: [ 1,2,3,4 ] /*  Dropdown Agent Names */
    Update Additional Attributes: [
      intiated_at: Time.now
    ]
  ]
}

Example 2:

{
  automation_name: "Chinese support"
  automation_description: "Assign the conversation to chinese support team if the language is chinese"
  automation_event: "Conversation Created" {dropdown}
  automation_conditions: [
    {
      automation_conditions_attribute: browser_language
      automation_conditions_operator: eq
      automation_conditions_value: cn
    }
  ]
  automation_actions: [
    Assing to the team: "Chinese support team"
  ]
}

Example 3:

{
  automation_name: "Update company name"
  automation_description: "Update company name conversation is started from company email id"
  automation_event: "Conversation Created" {dropdown}
  automation_conditions: [
    {
      automation_conditions_attribute: message
      automation_conditions_operator: present 
      automation_conditions_value: @company.com
    }
  ]
  automation_actions: [
    Update additional attributes: company name
  ]
}

Example 4:

{
  automation_name: "Conversation is related mobile"
  automation_description: "Assign the conversation to Jack conversation is related mobile"
  automation_event: "Conversation Created" {dropdown}
  automation_conditions: [
    {
      automation_conditions_attribute: message_content
      automation_conditions_operator: contains
      automation_conditions_value: mobile,

    }
  ]
  automation_actions: [
    Assing to a person: Jack
  ]
}

Example 5:

{
  automation_name: "Career related questions"
  automation_description: "Send message to career related messages"
  automation_event: "Conversation Created" {dropdown}
  automation_conditions: [
    {
      automation_conditions_attribute: label
      automation_conditions_operator: eq
      automation_conditions_value: career,
      query_operator: 'OR',
    },
    {
      automation_conditions_attribute: label
      automation_conditions_operator: eq
      automation_conditions_value: job,
      query_operator: 'OR',
    }
  ]
  automation_actions: [
    Send message: "Hey, Thank you for your interest. We don't have an open position available in chatwoot at the moment. If you could send your resume to hello@companyname.com, we would reach out if a matching position opens up in the future. Thank you again, and we wish you all the best in your job search"
  ]
}

cc @aswindevps @muhsin-k

@muhsin-k
Copy link
Member Author

muhsin-k commented Oct 13, 2021

Supported operators

  • Equal to
  • Not Equal
  • Is present
  • Is not present
  • Contains
  • Does not contain
  • Greater than (number, date)

@muhsin-k
Copy link
Member Author

muhsin-k commented Oct 15, 2021

Automation events

1. Conversation Created
2. Conversation Resolved
3. Assigned
4. Label Added
5. Label Removed
6. Conversation Snoozed
7. Conversation Auto Resolved
8. Conversation Muted
9. Team Assigned
10. New message created (Incoming/Outgoing)

Automation conditions

1. Select inbox (Option to select all or some inboxes)
2. Status - Open / Resolved / Pending / Snoozed / All
3. Contact - Contact or None
4. Team
5. Label or Labels
6. Message (Support regex)
7. Assignee - Person or None
8. Custom attributes (Contact or Conversation)
9. Additional attributes (Browser, City, Country_code, referer)
10. Contact fields (email, name, phone_number, last_activity_at, identifier)
11. Working hours


Automation actions

1. Send Message
2. Send Email
3. Resolve Conversation
4. Add Label
5. Update custom/additional attributes
6. Remove label
7. Snooze Conversation
8. Assign to agent
8. Assign to team
9. Send Transcript
10. Add support for sending webhook event 

@pranavrajs pranavrajs added this to the v1.22.0 milestone Oct 15, 2021
@voko3456
Copy link

voko3456 commented Oct 20, 2021

@muhsin-k @aswindevps @pranavrajs @tejaswinichile can you add automation action to send interactive session message so customer can replay by clicking the button and save his replay on custom attributes so we can implement local chat bot example :
whatsapp_illu_main_header_interactive_buttons_

@voko3456
Copy link

Automation events

1. Conversation Created
2. Conversation Resolved
3. Assigned
4. Label Added
5. Label Removed
6. Conversation Snoozed
7. Conversation Auto Resolved
8. Conversation Muted
9. Team Assigned
10. New message created (Incoming/Outgoing)

@muhsin-k
Please Add events
11-custom attributes updated
12-time since last message

@tejaswinichile
Copy link
Contributor

@voko3456 It's pretty early to quote if we can fulfill your requirement mentioned here #3195 (comment) in the next release, but we can have an initial message to send to the customer,

  1. if suppose the customer message contains a question related to food then we can send the related message as a reply.

After that how would we save the customer response, will take some time to decide.

But thanks for the requirement we would like to have that in our support system we would track that requirement in the different ticket.

@tejaswinichile
Copy link
Contributor

tejaswinichile commented Nov 8, 2021

Back End

@tejaswinichile
Copy link
Contributor

@sojan-official
Since we are handling dynamic event action trigger based on conditions, we need to have a publish-subscribe pattern to handle such implementation. Where subscribers will continuously listen to the event is being called and we will publish the event only when the condition matches. https://ably.com/topic/pub-sub I am thinking to add a gem for Automation Rules event handling.

We can do it without gem too but it will just fatten the models.
There are gems that can handle publish and subscribe patterns in rails.

Here are some examples:

  1. https://github.com/krisleech/wisper
  2. https://github.com/kevinrutherford/event_bus
  3. https://github.com/stevo/pubsub_on_rails

Please let me know if you think otherwise.

cc @pranavrajs @muhsin-k

@sojan-official
Copy link
Member

@tejaswinichile Sounds like a good direction. we already have pubsub mechanism in chatwoot using the wisper gem.

gem 'wisper', '2.0.0'

We can refactor and enhance the current list of events to support all the required event types.

module Events::Types

We can also add an automation listener which will react to these events based on the account configuration

def campaign_triggered(event)

@tejaswinichile
Copy link
Contributor

@sojan-official Okay then I will use the same gem. Thanks :)

@tejaswinichile tejaswinichile added Epic and removed feature-request This label is used to track new features which is a significant change to existing product labels Nov 10, 2021
@muhsin-k muhsin-k modified the milestones: v1.22.0, v2.0.0 Nov 16, 2021
@muhsin-k
Copy link
Member Author

muhsin-k commented Nov 16, 2021

Front End

@tejaswinichile
Copy link
Contributor

@muhsin-k
Just to confirm
Automation conditions will be applied to the conversation record which is mentioned in automation_event, correct?
Like if we have automation_event on conversation created and conditions browser language en so this condition will be applied on the record that was created in a recent event, right?

@tejaswinichile
Copy link
Contributor

tejaswinichile commented Nov 19, 2021

@sojan-official @muhsin-k

MVP for automation rule:


Event: Message Created

Supported Condition:

  1. Filter on message type [Incoming and outgoing]
  2. FIlter on substring e.g message contains words related to price assign it to the finance support team.

Supported Actions:

  1. Assign a team
  2. Add labels
  3. Send an email to the team

Event: Conversation Created

Supported Condition:

  1. Filter on conversation status [equal_to/not_equal_to]
  2. browser_name
  3. country_name
  4. referer link

Supported Actions:

  1. Assign a team
  2. Send an email to the team
  3. Assign an agent

Event: Conversation Updated

Supported Condition:

  1. Filter on conversation status [equal_to/not_equal_to]
  2. browser_name
  3. Assignee_id
  4. team_id
  5. country name
  6. referer link

Supported Actions:

  1. Assign a team
  2. Send an email to the team
  3. Assign an agent

@tejaswinichile
Copy link
Contributor

One update:

automation_actions: [
    Send Message: { Message: value },
    Add Label: [ priority_customer ],
    Assign best agents: [ Mutiselct of agents ]
    Update Custom Attributes: [
      attribute_key: attribute_value
    ]
    Pin the conversation: /* future scope */
  ]

Would look like this:

automation_actions: [
    { 
        action_name: send_message,
        action_params: 'Welcome aboard!' 
    },
    { 
        action_name: add_label,
        action_params: [priority_customer, finance_query] 
    },
    { 
        action_name: assign_agents,
        action_params:  [1,2,3,4] 
    },
    update_custom_attributes: [
      { attribute_key_1: attribute_value_1 },
      { attribute_key_2: attribute_value_2 }
    ]
  ]

@muhsin-k Please take note of this change.

@voko3456
Copy link

One update:

automation_actions: [
    Send Message: { Message: value },
    Add Label: [ priority_customer ],
    Assign best agents: [ Mutiselct of agents ]
    Update Custom Attributes: [
      attribute_key: attribute_value
    ]
    Pin the conversation: /* future scope */
  ]

Would look like this:

automation_actions: [
    { 
        action_name: send_message,
        action_params: 'Welcome aboard!' 
    },
    { 
        action_name: add_label,
        action_params: [priority_customer, finance_query] 
    },
    { 
        action_name: assign_agents,
        action_params:  [1,2,3,4] 
    },
    update_custom_attributes: [
      { attribute_key_1: attribute_value_1 },
      { attribute_key_2: attribute_value_2 }
    ]
  ]

@muhsin-k Please take note of this change.

@tejaswinichile @muhsin-k please don't forget to add the most important action is to send webhook when custom attributes updated or label added

@tejaswinichile
Copy link
Contributor

Notes:
Assign Teams: We assign only one team, so team dropdown would have a single selection.

Assign Best Agent: We assign only one agent, so the agent's dropdown would have a single selection.

Send email to the team: The team should be part of the account. This will require 2 params, one for team ids and the other for the email content.

@sojan-official
Copy link
Member

@tejaswinichile @muhsin-k potential use case

When phone number attribute of a contact gets updated 'Create conversation in an external Inbox with a specific message'

  • Trigger a WhatsApp conversation with a user through API
  • Switch the communication to SMS channel from live chat

ref: https://discord.com/channels/647412545203994635/719548534302441565/920414786691432548

@github-actions
Copy link

github-actions bot commented Aug 9, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants