Call WA bot function

emi_sastra
emi_sastra used Ask the Experts™
on
Hi All,

I want to send message to WA from desktop application using https://web.whatsapp.com/

Please see below code.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MaiWA
{
    public class CWhatsapp
    {
        private const string QR_CODE_XPATH = "//img[@alt='Scan me!']";
        private const string SEARCH_INPUT_XPATH = "//input[@title='Search or start new chat']";
        private const string CHAT_INPUT_XPATH = "//div[@class='_2S1VP copyable-text selectable-text']";
        //private static int TUNDA = 2000;
        private static IWebDriver _driver = null;

        public void StartWhatApp()
        {
            _driver = new ChromeDriver(new ChromeOptions { LeaveBrowserRunning = false });
            _driver.Url = "https://web.whatsapp.com";

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
            _driver.Navigate();
        }

        public bool OnLoginPage()
        {
            try
            {
                if (_driver.FindElement(By.XPath(QR_CODE_XPATH)) != null)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
            return false;
        }

        public void StopWhatApp()
        {
            _driver.Quit();
            _driver.Dispose();
        }

        public bool KirimText(string NomorWA, string Pesan)
        {
            var txtCariNoWa = _driver.FindElement(By.XPath(SEARCH_INPUT_XPATH));
            txtCariNoWa.SendKeys(NomorWA);
            txtCariNoWa.SendKeys(Keys.Enter);

            var txtPesan = _driver.FindElement(By.XPath(CHAT_INPUT_XPATH));
            txtPesan.SendKeys(Pesan);
            txtPesan.SendKeys(Keys.Enter);
            return true;
        }
    }
}

Open in new window


The question is how could I use it?

1. User should online using web.WA
2. Compile above to .dll
3. Call the .dll function.

For point 3, how could I do it?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakSenior Consultant
Awarded 2017
Distinguished Expert 2018

Commented:
From a new project, you can add a reference to either the DLL or the action project that you have created in 1 and 2

Author

Commented:
- From a new project, you can add a reference to either the DLL or the action project that you have created in 1 and 2
I know.

But which function (s) should I call ?

Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial