aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2018-08-09 20:18:50 -0300
committerMatias Linares <matiaslina@gmail.com>2018-08-09 20:18:50 -0300
commitee13d9e117fd82cf88c9bf28d6ce19b331aca1cb (patch)
tree48877b2575880b85ac37db88d584da44e264e2f2 /examples
parentf9587e831ce95650c90f5cb558a473a04f40520d (diff)
downloadperl6-matrix-client-ee13d9e117fd82cf88c9bf28d6ce19b331aca1cb.tar.gz
Add example to send a message
As requested in #12
Diffstat (limited to 'examples')
-rw-r--r--examples/send-message.p624
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/send-message.p6 b/examples/send-message.p6
new file mode 100644
index 0000000..4824be5
--- /dev/null
+++ b/examples/send-message.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl6
+use v6;
+use lib 'lib';
+use Matrix::Client;
+
+sub MAIN(:$room-id?, :$room-alias?, *@args) {
+ unless $room-id.so || $room-alias.so {
+ fail 'Missing room-id or room-alias';
+ }
+ my Matrix::Client $client .= new:
+ :home-server(%*ENV<MATRIX_HOMESERVER>),
+ :access-token($*ENV<MATRIX_ACCESS_TOKEN>);
+
+ my $id;
+ if $room-id.so {
+ $id = $room-id;
+ } else {
+ say "Searching for $room-alias";
+ $id = $client.get-room-id($room-alias);
+ }
+
+ my $event = $client.send($id, @args.join(' '));
+ say $event;
+}