mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	chore: Add seeds for Bot Messages (#1676)
This commit is contained in:
		| @@ -37,7 +37,7 @@ window.addEventListener('chatwoot:ready', function() { | ||||
|   console.log(window.$chatwoot); | ||||
|   window.$chatwoot.setUser('<%= user_id %>', { | ||||
|     identifier_hash: '<%= user_hash %>', | ||||
|     email: 'jane@acme.inc', | ||||
|     email: 'jane@example.com', | ||||
|     name: 'Jane Doe' | ||||
|   }); | ||||
| }) | ||||
|   | ||||
							
								
								
									
										16
									
								
								db/seeds.rb
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								db/seeds.rb
									
									
									
									
									
								
							| @@ -34,7 +34,7 @@ unless Rails.env.production? | ||||
|   InboxMember.create!(user: user, inbox: inbox) | ||||
|  | ||||
|   contact = Contact.create!(name: 'jane', email: 'jane@example.com', phone_number: '0000', account: account) | ||||
|   contact_inbox = ContactInbox.create!(inbox: inbox, contact: contact, source_id: user.id) | ||||
|   contact_inbox = ContactInbox.create!(inbox: inbox, contact: contact, source_id: user.id, hmac_verified: true) | ||||
|   conversation = Conversation.create!( | ||||
|     account: account, | ||||
|     inbox: inbox, | ||||
| @@ -44,6 +44,20 @@ unless Rails.env.production? | ||||
|     contact_inbox: contact_inbox, | ||||
|     additional_attributes: {} | ||||
|   ) | ||||
|  | ||||
|   # sample email collect | ||||
|   WootMessageSeeder.create_sample_email_collect_message conversation | ||||
|  | ||||
|   Message.create!(content: 'Hello', account: account, inbox: inbox, conversation: conversation, message_type: :incoming) | ||||
|  | ||||
|   # sample card | ||||
|   WootMessageSeeder.create_sample_cards_message conversation | ||||
|   # input select | ||||
|   WootMessageSeeder.create_sample_input_select_message conversation | ||||
|   # form | ||||
|   WootMessageSeeder.create_sample_form_message conversation | ||||
|   # articles | ||||
|   WootMessageSeeder.create_sample_articles_message conversation | ||||
|  | ||||
|   CannedResponse.create!(account: account, short_code: 'start', content: 'Hello welcome to chatwoot.') | ||||
| end | ||||
|   | ||||
							
								
								
									
										100
									
								
								lib/woot_message_seeder.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								lib/woot_message_seeder.rb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,100 @@ | ||||
| module WootMessageSeeder | ||||
|   def self.create_sample_email_collect_message(conversation) | ||||
|     Message.create!( | ||||
|       account: conversation.account, | ||||
|       inbox: conversation.inbox, | ||||
|       conversation: conversation, | ||||
|       message_type: :template, | ||||
|       content_type: :input_email, | ||||
|       content: 'Get notified by email' | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   def self.create_sample_cards_message(conversation) | ||||
|     Message.create!( | ||||
|       account: conversation.account, | ||||
|       inbox: conversation.inbox, | ||||
|       conversation: conversation, | ||||
|       message_type: :template, | ||||
|       content_type: 'cards', | ||||
|       content_attributes: { | ||||
|         items: [ | ||||
|           sample_card_item | ||||
|         ] | ||||
|       } | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   def self.sample_card_item | ||||
|     { | ||||
|       "media_url": 'https://i.imgur.com/d8Djr4k.jpg', | ||||
|       "title": 'Acme Shoes 2.0', | ||||
|       "description": 'Move with Acme Shoe 2.0', | ||||
|       "actions": [ | ||||
|         { | ||||
|           "type": 'link', | ||||
|           "text": 'View More', | ||||
|           "uri": 'http://acme-shoes.inc' | ||||
|         }, | ||||
|         { | ||||
|           "type": 'postback', | ||||
|           "text": 'Add to cart', | ||||
|           "payload": 'ITEM_SELECTED' | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   end | ||||
|  | ||||
|   def self.create_sample_input_select_message(conversation) | ||||
|     Message.create!( | ||||
|       account: conversation.account, | ||||
|       inbox: conversation.inbox, | ||||
|       conversation: conversation, | ||||
|       message_type: :template, | ||||
|       content: 'Your favorite food', | ||||
|       content_type: 'input_select', | ||||
|       content_attributes: { | ||||
|         "items": [ | ||||
|           { "title": '🌯 Burito', "value": 'Burito' }, | ||||
|           { "title": '🍝 Pasta', "value": 'Pasta' }, | ||||
|           { "title": ' 🍱 Sushi', "value": 'Sushi' }, | ||||
|           { "title": ' 🥗 Salad', "value": 'Salad' } | ||||
|         ] | ||||
|       } | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   def self.create_sample_form_message(conversation) | ||||
|     Message.create!( | ||||
|       account: conversation.account, | ||||
|       inbox: conversation.inbox, | ||||
|       conversation: conversation, | ||||
|       message_type: :template, | ||||
|       content_type: 'form', | ||||
|       content_attributes: { | ||||
|         "items": [ | ||||
|           { "name": 'email', "placeholder": 'Please enter your email', "type": 'email', "label": 'Email' }, | ||||
|           { "name": 'text_aread', "placeholder": 'Please enter text', "type": 'text_area', "label": 'Large Text' }, | ||||
|           { "name": 'text', "placeholder": 'Please enter text', "type": 'text', "label": 'text', "default": 'defaut value' } | ||||
|         ] | ||||
|       } | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   def self.create_sample_articles_message(conversation) | ||||
|     Message.create!( | ||||
|       account: conversation.account, | ||||
|       inbox: conversation.inbox, | ||||
|       conversation: conversation, | ||||
|       message_type: :template, | ||||
|       content: 'Tech Companies', | ||||
|       content_type: 'article', | ||||
|       content_attributes: { | ||||
|         "items": [ | ||||
|           { "title": 'Acme Hardware', "description": 'Hardware reimagined', "link": 'http://acme-hardware.inc' }, | ||||
|           { "title": 'Acme Search', "description": 'The best Search Engine', "link": 'http://acme-search.inc' } | ||||
|         ] | ||||
|       } | ||||
|     ) | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user
	 Sojan Jose
					Sojan Jose