/* send_hello.pl Author: Gimenez, Christian. Copyright (C) 2025 Gimenez, Christian This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . 2025-06-23 */ :- module(send_hello, [ ]). /** send_hello: A simple client that connects and sends a hello world! @author Christian Gimenez @license GPLv3 */ :- use_module(library(xmpp/xmpp)). :- use_module(library(xmpp/xmpp_core)). :- use_module(library(xmpp/xmpp_auth)). :- initialization(main, main). :- dynamic message_sent/0. %% opt_type(j, jid, atom). %% opt_type(t, jid_to, atom). %% opt_help(jid, 'Jabber ID to connect to'). %% opt_help(jid_to, 'Jabber ID to send a "hello"'). send_hello_msg(JIDTo, _) :- format('Sending message to ~s', [JIDTo]), nl, send_message(JIDTo, 'hello!', []), write('Sent!'), nl, flush, sleep(1), write('Disconnecting...'), nl, disconnect. end_program(_) :- asserta(message_sent). wait_until_send :- repeat, sleep(1), message_sent. connect_and_send(JID, Password, JIDTo) :- debug(xmpp), debug(xmpp_auth), debug, format('Connecting to ~s...', [JID]), nl, add_hook(after_connect, send_hello:send_hello_msg(JIDTo)), add_hook(after_disconnect, send_hello:end_program), connect(JID, Password). main(ArgV) :- argv_options(ArgV, [JID, JIDTo], _Options), format('~s password?', [JID]), nl, read_line_to_string(current_input, PasswordS), atom_string(Password, PasswordS), connect_and_send(JID, Password, JIDTo), wait_until_send.