Want to integrate the WhatsApp with ignition

Hello all,

Require integrating the WhatsApp with ignition platform.

So, how to do it from scratch?

Does the python pywhatkit library is useful or not?

because ignition current jython version 2.7 and pywhatkit is not available in to jython 2.7.

So, how to configure?

Looks like there's an API:

It's Graph rather than REST, but you could perhaps sill use it?

1 Like

In 8.3, (our upcoming release) our Twilio module is getting extended with support for Whatsapp, if you can wait for it.

4 Likes

Ok,
Is there currently a way to integrate with Ignition?
Is there an open-source platform that provides an API or is it possible through custom scripting?

Probably. What have you tried? The 'turn key' solution is not available until 8.3. Anything you can find in the meantime is going to take some effort on your part.

I mean is it possible to through webdev module for whatsApp integration?

You don't need Webdev for outgoing HTTP calls; you can use system.net.httpClient - you'll just have to figure out how to authenticate and make the appropriate requests to Whatsapp.

1 Like

I implemented an HTTP POST script in Ignition, which successfully sends messages via a Python-based Web API using the FastAPI framework.

Ignition HTTP POST SCRIPT.


	msg = "This is test message from ignition platform."
	client = system.net.httpClient()
	
	url = "http://localhost:5005/send"
	payload = system.util.jsonEncode({
	    "phone": "+7456887611445",
	    "message": msg
	})
	
	response = client.post(
	    url,
	    data=payload,
	    headers={"Content-Type": "application/json"}
	)
	
	params = {"message" : msg}
	system.db.runNamedQuery("insertWhatsAppMsg", params)

**API generate python script. ** (Run through CMD, for example python app.py)
FAST API

from fastapi import FastAPI, HTTPException, Request
from pydantic import BaseModel
import pywhatkit
import uvicorn
import asyncio

app = FastAPI()

# Define the expected request body
class MessageRequest(BaseModel):
    phone: str
    message: str

@app.post("/send")
async def send_message(req: MessageRequest):
    if not req.phone or not req.message:
        raise HTTPException(status_code=400, detail="Missing phone or message")

    try:
        await asyncio.to_thread(pywhatkit.sendwhatmsg_instantly,req.phone, req.message)
        return {"status": "success", "details": "Message sent"}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=5005)

Problem: Each time the HTTP POST script is triggered from Ignition, a new WhatsApp Web session is opened in the browser, causing the previous session to close. Ideally, WhatsApp Web should run in the background without launching a new browser window or tab on every execution.

Is it possible to execute WhatsApp Web in the background (headless mode or via backend service) when sending messages, so that the browser does not visibly open during each message trigger?

  • The user should only need to link WhatsApp Web to the mobile device once.
  • After the initial linking, message triggers should occur silently, without visibly opening WhatsApp Web in the browser.

You should not be calling system.net.httpClient() for every operation. The client object it returns is expected to be reused. Place that assignment outside your function at the outer level of a project library script module, so that it will be cached.

Still WhatsApp web session opened it into browser when executing script.

Script package

client = system.net.httpClient()

def sendWhatsAppMessage(phone, msg):
    url = "http://localhost:5005/send"
    payload = system.util.jsonEncode({
        "phone": phone,
        "message": msg
    })
	
    response = client.post(
        url,
        data=payload,
        headers={"Content-Type": "application/json"}
    )

    params = {"message": msg}
    system.db.runNamedQuery("insertWhatsAppMsg", params)

    return response

Above function executing from the ignition script console.

msg = httpUtils.sendWhatsAppMessage("+7456887611445", "This is test message")

I don't know enough about WhatsApp to help further. I don't think this is Ignition-controlled behavior. (The script console doesn't have any connection to a browser itself.)

1 Like

pywhatkit, evidently, works by opening and automating a browser tab, not via any kind of API access (ew).

This is 100% the behavior of your choice of external library, not an Ignition problem:

2 Likes

Ok, Will check and update it

Is it possible to execute WhatsApp Web in the background (headless mode or via backend service) when sending messages, so that the browser does not visibly open during each message trigger?

  • The user should only need to link WhatsApp Web to the mobile device once.
  • After the initial linking, message triggers should occur silently, without visibly opening WhatsApp Web in the browser.

You're asking me/this forum for help with someone else's third party Python library. Ask them for help.

2 Likes

Thank you @PGriffith and @pturmel for your guidance regarding WhatsApp integration.

If I need any further help, I’ll be message you regarding WhatsApp integration into Ignition.

Do not send me a private message. I do not provide free help in private, with just a few commercial exceptions (noted in my profile).

1 Like