WhatsappBot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/whatsapp_bot.rb +48 -0
  3. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0606a83ac659cd7ca4278dd9fc6854955d5797f6f8e10f52b0d4b5ed6e3b5e3f
4
+ data.tar.gz: abf44f341668f8226881f6a406de45913350be97211d34f180266e06e2c0cf38
5
+ SHA512:
6
+ metadata.gz: b224d3a8cc9ce0a5ecd62148db12a6092a63a7dff9546981d51eb13eab33d472bd56ebfe2d89ead5acba47b51c94a6301e0f00989aece6c78a448f66e72850be
7
+ data.tar.gz: 993235169ac2778d076cad3accc53dcd067097d46aaab8c32d7d3c10c52847f1078dc5b7429a049fc09356fdd6f4237369022326985fba837727ea18427753a7
@@ -0,0 +1,48 @@
1
+ require "selenium-webdriver"
2
+
3
+ class WhatsappBot
4
+ URL = "https://web.whatsapp.com/"
5
+
6
+ def initialize
7
+ @driver = Selenium::WebDriver.for :chrome
8
+ @driver.get(URL)
9
+ @driver.find_element(css: '[name="rememberMe"]').click
10
+ @logged_in = false
11
+ end
12
+
13
+ def logged_in?
14
+ @logged_in
15
+ end
16
+
17
+ def try_logging_in
18
+ @driver.find_element(class: "landing-title")
19
+ @logged_in = false
20
+ puts "Please log in with your phone in the chrome driver"
21
+ rescue Selenium::WebDriver::Error::NoSuchElementError => e
22
+ @logged_in = true
23
+ end
24
+
25
+ def send_message(to:, text:)
26
+ if (logged_in?)
27
+ return send_text_message(to, text)
28
+ else
29
+ if (try_logging_in)
30
+ return send_text_message(to, text)
31
+ end
32
+ puts "Not logged in"
33
+ return false
34
+ end
35
+ rescue Selenium::WebDriver::Error::NoSuchElementError => e
36
+ puts "Couldnt find the user please check if name is correct or try again after some seconds"
37
+ return false
38
+ end
39
+
40
+ private
41
+
42
+ def send_text_message(to, text)
43
+ @driver.find_element(css: "[title='#{to}']").click
44
+ @driver.find_element(css: "[contenteditable='true']").send_keys(text)
45
+ @driver.find_element(css: 'span[data-icon="send"]').click
46
+ return @driver.find_elements(css: ".message-out").last.text.include?(text)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: WhatsappBot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mujadded Al Rabbani Alif
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem lets you send whatsapp message without using its api only whats
14
+ app web. It lets you log in with webdriver and then you can send message with your
15
+ app. It can help if you want to make a app that can send message but you dont want
16
+ to buy any app
17
+ email: mujadded.alif@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/whatsapp_bot.rb
23
+ homepage: https://github.com/Mujadded/whatsapp_bot
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.7.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Send message in whatsapp without api
47
+ test_files: []