100% found this document useful (6 votes)
31 views

Building Telegram Bots: Develop Bots in 12 Programming Languages using the Telegram Bot API 1st Edition Nicolas Modrzyk 2024 scribd download

API

Uploaded by

nnekestiim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
31 views

Building Telegram Bots: Develop Bots in 12 Programming Languages using the Telegram Bot API 1st Edition Nicolas Modrzyk 2024 scribd download

API

Uploaded by

nnekestiim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Building Telegram Bots: Develop Bots in 12


Programming Languages using the Telegram Bot API
1st Edition Nicolas Modrzyk

https://textbookfull.com/product/building-telegram-bots-
develop-bots-in-12-programming-languages-using-the-telegram-
bot-api-1st-edition-nicolas-modrzyk/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Developing bots with Microsoft Bots Framework: create


intelligent bots using MS Bot Framework and Azure
Cognitive Services 1st Edition Srikanth Machiraju
https://textbookfull.com/product/developing-bots-with-microsoft-bots-
framework-create-intelligent-bots-using-ms-bot-framework-and-azure-
cognitive-services-1st-edition-srikanth-machiraju/
textboxfull.com

Introducing Azure Bot Service Building Bots for Business


Waghmare

https://textbookfull.com/product/introducing-azure-bot-service-
building-bots-for-business-waghmare/

textboxfull.com

Practical Bot Development: Designing and Building Bots


with Node.js and Microsoft Bot Framework Szymon Rozga

https://textbookfull.com/product/practical-bot-development-designing-
and-building-bots-with-node-js-and-microsoft-bot-framework-szymon-
rozga/
textboxfull.com

Building Bots with Microsoft Bot Framework Creating


intelligent conversational interfaces 1st Edition Kishore
Gaddam
https://textbookfull.com/product/building-bots-with-microsoft-bot-
framework-creating-intelligent-conversational-interfaces-1st-edition-
kishore-gaddam/
textboxfull.com
Designing Bots Creating Conversational Experiences 1st
Edition Amir Shevat

https://textbookfull.com/product/designing-bots-creating-
conversational-experiences-1st-edition-amir-shevat/

textboxfull.com

Practical Artificial Intelligence: Machine Learning, Bots,


and Agent Solutions Using C# 1st Edition Arnaldo Pérez
Castaño
https://textbookfull.com/product/practical-artificial-intelligence-
machine-learning-bots-and-agent-solutions-using-c-1st-edition-arnaldo-
perez-castano/
textboxfull.com

Java Image Processing Recipes: With OpenCV and JVM 1st


Edition Nicolas Modrzyk

https://textbookfull.com/product/java-image-processing-recipes-with-
opencv-and-jvm-1st-edition-nicolas-modrzyk/

textboxfull.com

Building Intelligent Cloud Applications Develop Scalable


Models Using Serverless Architectures with Azure 1st
Edition Vicente Herrera García
https://textbookfull.com/product/building-intelligent-cloud-
applications-develop-scalable-models-using-serverless-architectures-
with-azure-1st-edition-vicente-herrera-garcia/
textboxfull.com

Introduction to Deep Learning Business Applications for


Developers: From Conversational Bots in Customer Service
to Medical Image Processing Armando Vieira
https://textbookfull.com/product/introduction-to-deep-learning-
business-applications-for-developers-from-conversational-bots-in-
customer-service-to-medical-image-processing-armando-vieira/
textboxfull.com
Building
Telegram Bots
Develop Bots in 12 Programming
Languages using the Telegram
Bot API

Nicolas Modrzyk
Building Telegram
Bots
Develop Bots in
12 Programming Languages
using the Telegram Bot API

Nicolas Modrzyk
Building Telegram Bots: Develop Bots in 12 Programming Languages using
the Telegram Bot API
Nicolas Modrzyk
Tokyo, Tokyo, Japan

ISBN-13 (pbk): 978-1-4842-4196-7 ISBN-13 (electronic): 978-1-4842-4197-4


https://doi.org/10.1007/978-1-4842-4197-4
Library of Congress Control Number: 2018965498

Copyright © 2019 by Nicolas Modrzyk


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image, we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the author nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Nikhil Karkal
Development Editor: Matthew Moodie
Coordinating Editor: Divya Modi
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science+Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-4196-7.
For more detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author���������������������������������������������������������������������������������ix
About the Technical Reviewers�����������������������������������������������������������xi
Acknowledgments�����������������������������������������������������������������������������xiii
Introduction����������������������������������������������������������������������������������������xv

Chapter 1: Week 1: Ruby����������������������������������������������������������������������1


Chatting with the BotFather����������������������������������������������������������������������������������1
Setting Up Ruby����������������������������������������������������������������������������������������������������7
Your First Telegram Bot�����������������������������������������������������������������������������������������8
Understanding Received Messages Fields���������������������������������������������������������14
First Reply�����������������������������������������������������������������������������������������������������������15

Chapter 2: Week 2: Nim����������������������������������������������������������������������17


Installing Nim������������������������������������������������������������������������������������������������������17
Nim Plug-in for Visual Studio Code���������������������������������������������������������������������18
Hello, Nim������������������������������������������������������������������������������������������������������������20
Second Nim Program (Still Not Bot)��������������������������������������������������������������������23
Creating Visual Studio Code Build Tasks�������������������������������������������������������������25
Installing Nim Packages with Nimble�����������������������������������������������������������������29
First Nim Bot�������������������������������������������������������������������������������������������������������31
Replying to Nim Bot��������������������������������������������������������������������������������������������33
Cats and Dogs Nim Bot���������������������������������������������������������������������������������������34

iii
Table of Contents

Chapter 3: Week 3: Crystal�����������������������������������������������������������������37


Setting Up Crystal�����������������������������������������������������������������������������������������������38
Short Walk in the Playground������������������������������������������������������������������������������39
Going Visual Studio Code Again��������������������������������������������������������������������������41
Creating a Crystal Project�����������������������������������������������������������������������������������46
Echo Bot��������������������������������������������������������������������������������������������������������������50
Command Bot�����������������������������������������������������������������������������������������������������52

Chapter 4: Week 4: Rust���������������������������������������������������������������������57


Rust Installation and First Steps�������������������������������������������������������������������������58
Installation�����������������������������������������������������������������������������������������������������58
First Rust or Two�������������������������������������������������������������������������������������������������62
Hello Rust������������������������������������������������������������������������������������������������������62
Fibonacci�������������������������������������������������������������������������������������������������������64
Ride the cargo�����������������������������������������������������������������������������������������������������66
We Have Time������������������������������������������������������������������������������������������������66
Multiple Cargo Targets����������������������������������������������������������������������������������������70
Rust Bot Number 1: Reply to Me�������������������������������������������������������������������������74
Rust Bot Number 2: Where Is Tokyo?������������������������������������������������������������������77
Rust Bot Number 3: Chained Reaction����������������������������������������������������������������82
Compiling for Release�����������������������������������������������������������������������������������������84

Chapter 5: Week 5: D��������������������������������������������������������������������������85


Installation and First D Steps������������������������������������������������������������������������������86
Some Bits of D on Concurrency��������������������������������������������������������������������������91
Simple Threading�������������������������������������������������������������������������������������������91
Thread with a State���������������������������������������������������������������������������������������92
Shared State��������������������������������������������������������������������������������������������������94

iv
Table of Contents

A Few More Examples of D���������������������������������������������������������������������������������95


Sort Me Tender, Sort Me True�������������������������������������������������������������������������95
My Love for Fibonacci�����������������������������������������������������������������������������������98
Telegram Bots in D��������������������������������������������������������������������������������������������100
Meet dub�����������������������������������������������������������������������������������������������������������100
First D Bot����������������������������������������������������������������������������������������������������105
More Bot API Usage�������������������������������������������������������������������������������������107

Chapter 6: Week 6: C++��������������������������������������������������������������������111


Requirements, Installation, and First Bot����������������������������������������������������������111
Install tgbot-cpp������������������������������������������������������������������������������������������112
Install OpenCV���������������������������������������������������������������������������������������������113
File Download Program�������������������������������������������������������������������������������113
Echo Bot������������������������������������������������������������������������������������������������������������119
C++ Bots�����������������������������������������������������������������������������������������������������������123
Bot with Inline Keyboard�����������������������������������������������������������������������������123
Photo Bot�����������������������������������������������������������������������������������������������������126
OpenCV in action�����������������������������������������������������������������������������������������������128
OpenCV Sample Program����������������������������������������������������������������������������128
OpenCV Bot�������������������������������������������������������������������������������������������������������131

Chapter 7: Week 7: Clojure���������������������������������������������������������������135


Initial Setup and First Clojure Bot���������������������������������������������������������������������136
Visual Studio Code���������������������������������������������������������������������������������������141
The Project Metadata in project.clj��������������������������������������������������������������142
The Clojure Code in core.clj�������������������������������������������������������������������������143
The Token!���������������������������������������������������������������������������������������������������146
Debugging Telegram Messages�������������������������������������������������������������������146

v
Table of Contents

Creating a Reverse Bot��������������������������������������������������������������������������������148


Inline Handler����������������������������������������������������������������������������������������������149
A Simple Weather Bot���������������������������������������������������������������������������������������150
OpenCV and Telegram: Origami Bot������������������������������������������������������������������154

Chapter 8: Week 8: Java�������������������������������������������������������������������159


Installation��������������������������������������������������������������������������������������������������������159
The Project Structure����������������������������������������������������������������������������������161
The build.gradle file�������������������������������������������������������������������������������������161
Visual Studio Code Setup����������������������������������������������������������������������������164
First Java Bot����������������������������������������������������������������������������������������������������165
Send Some Text�������������������������������������������������������������������������������������������167
Send a Photo�����������������������������������������������������������������������������������������������169
Bot with Invoice Capabilities�����������������������������������������������������������������������������170
Asking Permission���������������������������������������������������������������������������������������170
Sending an Invoice Message����������������������������������������������������������������������������173

Chapter 9: Week 9: Go����������������������������������������������������������������������181


Installation of Go�����������������������������������������������������������������������������������������������182
Let’s Go�������������������������������������������������������������������������������������������������������������184
Let’s Fib������������������������������������������������������������������������������������������������������������190
First Bot in Go���������������������������������������������������������������������������������������������������193
Just Sending Pictures���������������������������������������������������������������������������������������197

Chapter 10: Week 10: Elixir��������������������������������������������������������������201


Installation��������������������������������������������������������������������������������������������������������202
Using iex������������������������������������������������������������������������������������������������������203
Using mix�����������������������������������������������������������������������������������������������������204
Running iex with mix�����������������������������������������������������������������������������������205

vi
Table of Contents

Project Structure of a mix Project���������������������������������������������������������������������206


config.exs����������������������������������������������������������������������������������������������������207
mix.exs��������������������������������������������������������������������������������������������������������208
Dependencies����������������������������������������������������������������������������������������������209
telegrambox.ex��������������������������������������������������������������������������������������������212
(Back to) Dependencies�������������������������������������������������������������������������������213
Get Something��������������������������������������������������������������������������������������������������216
GetMe����������������������������������������������������������������������������������������������������������216
GetChat��������������������������������������������������������������������������������������������������������217
GetFile���������������������������������������������������������������������������������������������������������218
Using Elixir’s System�����������������������������������������������������������������������������������219
SendPhoto���������������������������������������������������������������������������������������������������220
Telegram Bot�����������������������������������������������������������������������������������������������������221
Bot1: Anything Goes������������������������������������������������������������������������������������221
Bot2: Fibonacci��������������������������������������������������������������������������������������������222

Chapter 11: Week 11: Node.js�����������������������������������������������������������225


Meet RunKit������������������������������������������������������������������������������������������������������226
Creating an Account������������������������������������������������������������������������������������226
First Code on RunKit������������������������������������������������������������������������������������229
A Certain Je Ne Sais Koa�����������������������������������������������������������������������������230
Publishing Some Koa�����������������������������������������������������������������������������������232
Telegram Bot with Webhooks����������������������������������������������������������������������������234
More on the Telegraf Library�����������������������������������������������������������������������������239
Image-to-Chat Example�������������������������������������������������������������������������������239
RegExp, Inline Keyboards, and Embedded Emojis���������������������������������������240

vii
Table of Contents

Running Node.js Locally������������������������������������������������������������������������������������242


Setting Up Node.js���������������������������������������������������������������������������������������243
Using Local Tunnel���������������������������������������������������������������������������������������244

Chapter 12: Week 12: Python�����������������������������������������������������������247


Installation��������������������������������������������������������������������������������������������������������248
A Few Python Programs������������������������������������������������������������������������������������250
Fibonacci 1��������������������������������������������������������������������������������������������������250
Fibonacci 2��������������������������������������������������������������������������������������������������252
Fibonacci 3��������������������������������������������������������������������������������������������������253
Fibonacci 4��������������������������������������������������������������������������������������������������254
Fibonacci 5��������������������������������������������������������������������������������������������������255
First Telegram with Python�������������������������������������������������������������������������������256
First Bot: Send a Random Photo�����������������������������������������������������������������������258
First OpenCV Bot: Changing the Color Space of a Picture���������������������������������260
Second OpenCV Bot: Count Faces���������������������������������������������������������������������262
TensorFlow to Close the Show��������������������������������������������������������������������������265

Index�������������������������������������������������������������������������������������������������271

viii
About the Author
Nicolas Modrzyk has more than 15 years of
IT experience in Asia, Europe, and the United
States and is currently CTO of an international
consulting company in Tokyo, Japan. He is
the author of four other published books,
mostly focused on the Clojure language and
expressive code. When not bringing new
ideas to customers, he spends time with his
two fantastic daughters, Mei and Manon, and
playing live music internationally.

ix
About the Technical Reviewers
Dushyant Rathore is currently working as
a firmware engineer with Western Digital.
His experience includes full-stack web
development, machine learning, decentralized
applications, and others. Dushyant has worked
on several kinds of projects related to IoT,
chatbots, web sites, scrapers, command-
line tools, and machine learning projects,
among others, at various startups. He has participated in national and
international hackathons and has won a few of them. He is a big cloud
computing enthusiast.

Sham Satyaprasad has been a full-stack


software developer for more than four years,
having completed a master’s degree in
embedded systems from Manipal University.
He prides himself on writing highly efficient,
readable, and maintainable code and strongly
believes that coding is an art as much as it is
science. Sham has recently developed a keen
interest in NLP, ML, and data science and has been busy wrapping his
head around these topics.

xi
Acknowledgments
It’s been yet another typing race to get this book out on time and beat the
odds. Divya and Nikhil, thank you so much for teaming up again. I’m really
looking forward to our next collaboration!
I received support from so many people that it would take another
book just to write the list of names. Nevertheless…
Thank you to my sister, Emily, my brother, Gregor, Mum and Dad,
family, cousins, uncles, aunts, friends, Abe-san, Sawada-san, Gucci,
Marshall, Momo, my soulmate Sachiko, soccer friends (I would break a
knee for you), the Irish crew still enjoying Guinness (one more for me!),
the awesome people in America (who always find the LPs I’m missing),
Chris and the Biners, the French team that’s always there to support
me, even without being asked, and the people deep in my heart, for
your never-­ending support. I could not have finished this without you.
I appreciate you all so much.
And, of course, thank you to my two wonderful daughters, Mei and
Manon, for keeping up and always doing your best, even during hard
times. You rock! I love you.

xiii
Introduction
With a hundred ways to do a dozen things, why not try it all?
—Julian Casablancas

Have you ever wondered how you could accomplish more by doing less,
how you could have a sort of double who does all the work while you enjoy
some cool beachside or spend more outdoor time with your beautiful
children? I always have.
I am a big fan of the Telegram chat platform. Let’s call it a platform,
because it is more than a simple chat service with which you can stay in
touch with people who matter to you most. It also enables you to think in
ways you haven’t before.
For example, living in Tokyo, you always care about what time the last
train home is going to depart. I guess most people in big cities around the
globe probably have that same concern. Checking the clock only every so
often can result in a terrible and/or expensive taxi ride, so I started wanting
something that automatically offered me a bunch of options to get home.
The first bot I wrote was to tell me the schedule of the last few trains
home and some different options, from the easiest to reach before the last
few departures to the very latest, which I would have to dash to catch. That
saved me quite a bit of money.
The second bot I wrote was slightly more IoT-oriented. It used a
webcam to send me via Telegram pictures of people who rang my doorbell.
The third one, I also remember, was kind of stupid. It was to use a mini
projector to display the most recent message coming through a Telegram
chat room. (It’s very entertaining to view random messages during a small
party at home.)

xv
Introduction

But there are so many things for which to try to build a bot—search
for a plane ticket, check your fridge, etc. Having a bot is a simple way
to facilitate all the things you do daily, using the same kind of simple
Telegram chat rooms to get answers to questions related to daily life or to
issue commands and conquer the world.
This relatively short book is about learning how to write Telegram
bots in several different programming languages. Why not use one
and stick to it? you might ask. Well, because there’s not one answer to
all questions, and what’s right for others might not be suitable for you.
Exploring different programming languages is also a fun way to examine
the strengths of each language while performing the same tasks. Each of
the Telegram concepts can be introduced one after the other, in a simple
fashion.
Or, you could just jump in and choose the language you want to try and
get started in no time. Some people want it to happen; some wish it would
happen; others make it happen. So, enjoy reading this book, and make it
happen.

xvi
CHAPTER 1

Week 1: Ruby
Mindful Monday Humans, may your coffee kick in before
reality does.
—Napz Cherub Pellazo

Ruby took the world by storm a while ago, owing to the ease and concision
of the code you can write with it. Most programmers have a sweet spot for
Ruby, and when their shell scripts and day-to-day lives get too messy, they
are usually very quick to switch to Ruby.
This first chapter is a bit special, because on top of creating a client
for our bot, I must also introduce you to how to create the bot itself.
Throughout the book, this first bot will be reused at will, although, of
course, the same steps used to make it could be used to create a bot army
and conquer the world!

C
 hatting with the BotFather
To register your own Telegram bot, you must talk to the father of all bots.
This bot father has a name, BotFather; Brad or Vladimir just doesn’t cut it.
He can be reached via Telegram as @BotFather.
BotFather does not sleep and can be reached at any time of day.
BotFather does take showers and always looks fresh. Here is the last profile
picture we have of this handsome bot (Figure 1-1).

© Nicolas Modrzyk 2019 1


N. Modrzyk, Building Telegram Bots, https://doi.org/10.1007/978-1-4842-4197-4_1
Chapter 1 Week 1: Ruby

Figure 1-1. BotFather’s latest profile picture

Finding BotFather is not so difficult; you just have to type his name,
“@BotFather,” in the Telegram list of people in the search box of your
Telegram client (Figure 1-2).

Figure 1-2. Looking for BotFather

2
Chapter 1 Week 1: Ruby

In the preceding list, the name is the one at the bottom. Next, start a
new chat with BotFather by clicking it.
Once the chat is started, you will also be welcomed by our handsome
bot, with a cordial message about APIs, free help, and an invitation to start
the chat (Figure 1-3).

Figure 1-3. Ready?

Once the chat has begun (by pressing the Start button that you can see
at the bottom), you are welcomed by BotFather with a bunch of options on
how to create or edit your list of bots (Figure 1-4).

3
Chapter 1 Week 1: Ruby

Figure 1-4. Say hello to BotFather

4
Chapter 1 Week 1: Ruby

Great! I won’t review the full list of options now but will start just by
creating our new bot. This is done here by typing in the /newbot command
and then following a simple conversation, such as the one in Figure 1-5.

Figure 1-5. Ask BotFather, please, please, for a new bot

Your bot is now ready to use. Can you see in red something like a
secret code? This is the bot token, which is a chain of characters that
will be used to uniquely identify and authenticate your bot against
the Telegram platform. Do not give away this token. Don’t write it in
a book or allow it to hang somewhere on GitHub, especially now that
Microsoft owns it.

5
Chapter 1 Week 1: Ruby

In our case, in the preceding chat, the token that was generated and
given to use is the one following:

624028896:AAFGfIXp3FEPtX1_S2zmHodHRNpu_wD1acA

If your token, like this one, ever becomes compromised, you can use
the /token command with the bot father, to generate a new token, as
shown in the conversation in Figure 1-6.

Figure 1-6. Chat to generate a new token

Alright, the registration of our Telegram bot is all done. So, let’s switch
to a little bit of coding in Ruby.

6
Chapter 1 Week 1: Ruby

S
 etting Up Ruby
Ruby, on most Unix-like platforms, including OS X, is already installed,
or it can be installed using a package manager. For those running lesser
operating systems, like Windows, you can download and install the Ruby
installer (Figure 1-7) from the Ruby download page at www.ruby-lang.
org/en/downloads/. Download the most recent version.

Figure 1-7. Looking for the Windows Ruby installer

After the installation is complete, if you open a terminal (on macOS),


or a command prompt on Windows (Figure 1-8), and can type in the
following commands without getting an error, you are all set:

ruby -v
gem -v

7
Chapter 1 Week 1: Ruby

Figure 1-8. Checking ruby and gem versions

If you have never used Ruby before, you may be wondering what the
gem executable is? It’s simply a Ruby-specific installer for libraries (just like
npm is for Node and pip is for Python), so when you require some open
source library that has been written by someone else, you would use gem to
get it on your machine and the ruby executable to run it.
Apart from Ruby, to have some coding fun outside Notepad, you also
need a text editor, so I propose to use Microsoft’s Visual Studio Code
(https://code.visualstudio.com/), but, of course, any of your favorite
text editors will do.
Alright, let’s get started and code our first bot.

Your First Telegram Bot


To get to talk to our first bot, we will use the Ruby library named
telegram_bot. There are a few other famous libraries that you can find
on RubyGems (https://rubygems.org/), but I find this library to be an
easy one to start and get going with, and I hope you come to agree with
me about this in time.
Actually, you can check for yourself and find your favorite Telegram
library, by querying the RubyGems web site (Figure 1-9).

8
Chapter 1 Week 1: Ruby

Figure 1-9. Looking for gems

To use a library in Ruby, you install it on your machine first, to make it


available to your computer, by using the gem install command, and then
in your Ruby code, you use the *require* function, to make that library
available to your Ruby program.
Let’s create a new folder for this first bot. Change the directory and
then install the Telegram library with gem, as shown following:

mkdir chapter-01
cd chapter-01
gem install telegram_bot

9
Chapter 1 Week 1: Ruby

At the terminal, the output should be something similar to this:

SuperPinkicious:chapter-01 niko$ gem install telegram_bot


Successfully installed telegram_bot-0.0.8
Parsing documentation for telegram_bot-0.0.8
Done installing documentation for telegram_bot after 0 seconds
1 gem installed

The gem is now installed and ready to be used in your code.


Now, you are going to write some code to wake up your bot and make
it come alive. In a new file in that folder, which you can name step0.rb, for
example, let’s write the following lines of Ruby code:

require 'telegram_bot'

bot = TelegramBot.new(token: ENV['BOT_TOKEN'])


bot.get_updates() do |message|
    puts message.to_s
end

What that code does is

• Make the telegram_bot library, installed via gem,


available to your program
• Create a new Ruby bot object, using the Telegram
token exposed via an external variable. This is usually
the recommended way to share your bot code without
giving your bot token to everyone.

• Get the bot instance instantiated, to listen for incoming


messages, using the bot object get_updates() method

• Ensure that, now, whenever a message is sent to the


bot, the bot will print it on the console

10
Chapter 1 Week 1: Ruby

To run the preceding written program on your machine, you pass the
name of the program file, step0.rb, to the ruby executable. Let’s do it.
At the terminal, execute the following command:

ruby  step0.rb

Observe the output (Figure 1-10).

Figure 1-10. Sometimes, it just does not work

Oops! That did not go so well. We forgot to pass the Telegram token to
our program.
This can be done on Linux or OS X with the following:

export BOT_TOKEN='585672177:AAHswpmdA2zP52ZWoJMdteGa0xQ8KeynWvE'

And on Windows with

set BOT_TOKEN=585672177:AAHswpmdA2zP52ZWoJMdteGa0xQ8KeynWvE

Let’s run the program again. This time, it looks like the command
is not finishing… This is expected, as the bot is now actually waiting for
messages.
Let’s be the one to start the conversation, so let’s send a greeting
message.
In the Telegram window, search for the bot and start chatting
(Figure 1-­11).

11
Chapter 1 Week 1: Ruby

Figure 1-11. First message to our bot

By pressing that Start button, the bot is already receiving a message


(Figure 1-12)!

Figure 1-12. First message from our bot!

Hmmm, that was not very readable. With Ruby, you can display a more
legible version of any object, by using the to_yaml function. Let’s update
the code and see what happens.
We call require 'yaml', to import it into the Ruby namespace, and
now we can call the to_yaml on the message the bot has received.

require 'telegram_bot'
require 'yaml'
bot = TelegramBot.new(token: ENV['BOT_TOKEN'])

12
Chapter 1 Week 1: Ruby

bot.get_updates() do |message|
    # puts message.to_s
    puts message.to_yaml
end

You would have to type Ctrl-C to terminate the running version of the
bot first and then start the new bot, by executing the ruby command again.
Figure 1-13 shows the outcome.

Figure 1-13. How are you?

In the console, or in the terminal where the bot was started, you now
can see a more detailed version of the received message.

endSuperPinkicious:chapter-01 niko$ ruby step0.rb


--- !ruby/object:TelegramBot::Message
message_id: 191
from: !ruby/object:TelegramBot::User
  id: 121843071
  first_name: Nico
  last_name: Nico
  username: hellonico
chat: !ruby/object:TelegramBot::Channel
  id: 121843071
  username: hellonico
  title:
date: !ruby/object:DateTime 2018-08-31 07:42:26.000000000 Z
text: how are you?
reply_to_message:

13
Chapter 1 Week 1: Ruby

Actually, whatever the programming language used, this message


format is going to be quite consistent, so it’s a good idea to have a look at
the message fields.

Understanding Received Messages Fields


Table 1-1 briefly explains the fields we have just received via the
Telegram bot.

Table 1-1. Fields Received from the Telegram Bot


Field Sample Value Explanation

message_id 191 The unique identifier


of the bot message
from !ruby/object:TelegramBot::User The user who sent
the message
chat !ruby/object:TelegramBot::Channel The chat/channel
information
date !ruby/object:DateTime 2018-08-­31 When the message
07:42:26.000000000 Z was sent
text how are you? The text of the
message
reply_to_ <empty> The message that
message this message was a
reply to

For standard messages, there is not much beyond what you would
expect from a chat message object. You will probably use the date, text,
and from fields most of the time.

14
Chapter 1 Week 1: Ruby

F irst Reply
Again, Ruby’s concision makes it quite easy to create strings from objects.
With the following, you can use blocks of executable code directly within a
string: #{}.
This makes it very powerful for templated messages, and in our case,
for bot programming. Within the get_updates() call block, let’s now write
and send a reply.

    message.reply do |reply|
        reply.text = "Hello, #{message.from.first_name}!"
        reply.send_with(bot)
end

After restarting the bot (Ctrl-C, ruby step0.rb), we can start a more
talkative version of this Ruby bot (Figure 1-14).

Figure 1-14. Hello, Nico!

That worked pretty smoothly, and I am happy to announce that you


have moved to level 2 of this bot master course.

15
Exploring the Variety of Random
Documents with Different Content
3

When Lady Molly heard this theory she laughed, and shrugged her
pretty shoulders.
“Old Mr. Frewin was dying, was he not, at the time of the
burglary?” she said. “Why should his wife, soon to become his
widow, take the trouble to go through a laboured and daring comedy
of a burglary in order to possess herself of things which would
become hers within the next few hours? Even if, after Mr. Frewin’s
death, she could not actually dispose of the miniatures, the old man
left her a large sum of money and a big income by his will, with
which she could help her spendthrift son as much as she pleased.”
This was, of course, why the mystery in this strange case was so
deep. At the Yard they did all that they could. Within forty-eight hours
they had notices printed in almost every European language, which
contained rough sketches of the stolen miniatures hastily supplied by
Mrs. Frewin herself. These were sent to as many of the great
museums and art collectors abroad as possible, and of course to the
principal American cities and to American millionaires. There is no
doubt that the thief would find it very difficult to dispose of the
miniatures, and until he could sell them his booty would, of course,
not benefit him in any way. Works of art cannot be tampered with, or
melted down or taken to pieces, like silver or jewellery, and, so far as
could be ascertained, the thief did not appear to make the slightest
attempt to dispose of the booty, and the mystery became more dark,
more impenetrable than ever.
“Will you undertake the job?” said the chief one day to Lady Molly.
“Yes,” she replied, “on two distinct conditions.”
“What are they?”
“That you will not bother me with useless questions, and that you
will send out fresh notices to all the museums and art collectors you
can think of, and request them to let you know of any art purchases
they may have made within the last two years.”
“The last two years!” ejaculated the chief, “why, the miniatures
were only stolen three months ago.”
“Did I not say that you were not to ask me useless questions?”
This to the chief, mind you; and he only smiled, whilst I nearly fell
backwards at her daring. But he did send out the notices, and it was
generally understood that Lady Molly now had charge of the case.
4

It was about seven weeks later when, one morning, I found her at
breakfast looking wonderfully bright and excited.
“The Yard has had sheaves of replies, Mary,” she said gaily, “and
the chief still thinks I am a complete fool.”
“Why, what has happened?”
“Only this, that the art museum at Budapest has now in its
possession a set of eight miniatures by Engleheart; but the
authorities did not think that the first notices from Scotland Yard
could possibly refer to these, as they had been purchased from a
private source a little over two years ago.”
“But two years ago the Frewin miniatures were still at Blatchley
House, and Mr. Frewin was fingering them daily,” I said, not
understanding, and wondering what she was driving at.
“I know that,” she said gaily, “so does the chief. That is why he
thinks that I am a first-class idiot.”
“But what do you wish to do now?”
“Go to Brighton, Mary, take you with me and try to elucidate the
mystery of the Frewin miniatures.”
“I don’t understand,” I gasped, bewildered.
“No, and you won’t until we get there,” she replied, running up to
me and kissing me in her pretty, engaging way.
That same afternoon we went to Brighton and took up our abode
at the Hotel Metropole. Now you know I always believed from the
very first that she was a born lady and all the rest of it, but even I
was taken aback at the number of acquaintances and smart friends
she had all over the place. It was “Hello, Lady Molly! whoever would
have thought of meeting you here?” and “Upon my word! this is good
luck,” all the time.
She smiled and chatted gaily with all the folk as if she had known
them all her life, but I could easily see that none of these people
knew that she had anything to do with the Yard.
Brighton is not such a very big place as one would suppose, and
most of the fashionable residents of the gay city find their way
sooner or later to the luxurious dining-room of the Hotel Metropole, if
only for a quiet little dinner given when the cook is out. Therefore I
was not a little surprised when, one evening, about a week after our
arrival and just as we were sitting down to the table d’hôte dinner,
Lady Molly suddenly placed one of her delicate hands on my arm.
“Look behind you, a little to your left, Mary, but not just this minute.
When you do you will see two ladies and two gentlemen sitting at a
small table quite close to us. They are Sir Michael and Lady Steyne,
the Honourable Mrs. Frewin in deep black, and her son, Mr. Lionel
Frewin.”
I looked round as soon as I could, and gazed with some interest at
the hero and heroine of the Blatchley House drama. We had a quiet
little dinner, and Lady Molly having all of a sudden become very
silent and self-possessed, altogether different from her gay, excited
self of the past few days, I scented that something important was in
the air, and tried to look as unconcerned as my lady herself. After
dinner we ordered coffee, and as Lady Molly strolled through into the
lounge, I noticed that she ordered our tray to be placed at a table
which was in very close proximity to one already occupied by Lady
Steyne and her party.
Lady Steyne, I noticed, gave Lady Molly a pleasant nod when we
first came in, and Sir Michael got up and bowed, saying “How d’ye
do?” We sat down and began a desultory conversation together.
Soon, as usual, we were joined by various friends and
acquaintances who all congregated round our table and set
themselves to entertaining us right pleasantly. Presently the
conversation drifted to art matters, Sir Anthony Truscott being there,
who is, as you know, one of the keepers of the Art Department at
South Kensington Museum.
“I am crazy about miniatures just now,” said Lady Molly in
response to a remark from Sir Anthony.
I tried not to look astonished.
“And Miss Granard and I,” continued my lady, quite unblushingly,
“have been travelling all over the Continent in order to try and secure
some rare specimens.”
“Indeed,” said Sir Anthony. “Have you found anything very
wonderful?”
“We certainly have discovered some rare works of art,” replied
Lady Molly, “have we not, Mary? Now the two Englehearts we
bought at Budapest are undoubtedly quite unique.”
“Engleheart—and at Budapest!” remarked Sir Anthony. “I thought I
knew the collections at most of the great Continental cities, but I
certainly have no recollection of such treasures in the Hungarian
capital.”
“Oh, they were only purchased two years ago, and have only been
shown to the public recently,” remarked Lady Molly. “There was
originally a set of eight, so the comptroller, Mr. Pulszky, informed me.
He bought them from an English collector whose name I have now
forgotten, and he is very proud of them, but they cost the country a
great deal more money than it could afford, and in order somewhat
to recoup himself Mr. Pulszky sold two out of the eight at, I must say,
a very stiff price.”
While she was talking I could not help noticing the strange glitter in
her eyes. Then a curious smothered sound broke upon my ear. I
turned and saw Mrs. Frewin looking with glowing and dilated eyes at
the charming picture presented by Lady Molly.
“I should like to show you my purchases,” said the latter to Sir
Anthony. “One or two foreign connoisseurs have seen the two
miniatures and declare them to be the finest in existence. Mary,” she
added, turning to me, “would you be so kind as to run up to my room
and get me the small sealed packet which is at the bottom of my
dressing-case? Here are the keys.”
A little bewildered, yet guessing by her manner that I had a part to
play, I took the keys from her and went up to her room. In her
dressing-case I certainly found a small, square, flat packet, and with
that in my hand I prepared to go downstairs again. I had just locked
the bedroom door when I was suddenly confronted by a tall, graceful
woman dressed in deep black, whom I at once recognised as the
Honourable Mrs. Frewin.
“You are Miss Granard?” she said quickly and excitedly; her voice
was tremulous and she seemed a prey to the greatest possible
excitement. Without waiting for my reply she continued eagerly:
“Miss Granard, there is no time to be more explicit, but I give you
my word, the word of a very wretched, heart-broken woman, that my
very life depends upon my catching a glimpse of the contents of the
parcel that you now have in your hand.”
“But——” I murmured, hopelessly bewildered.
“There is no ‘but,’ ” she replied. “It is a matter of life and death.
Here are £200, Miss Granard, if you will let me handle that packet,”
and with trembling hands she drew a bundle of bank-notes from her
reticule.
I hesitated, not because I had any notion of acceding to Mrs.
Frewin’s request, but because I did not quite know how I ought to act
at this strange juncture, when a pleasant, mellow voice broke in
suddenly:
“You may take the money, Mary, if you wish. You have my
permission to hand the packet over to this lady,” and Lady Molly,
charming, graceful and elegant in her beautiful directoire gown,
stood smiling some few feet away, with Hankin just visible in the
gloom of the corridor.
She advanced towards us, took the small packet from my hands,
and held it out towards Mrs. Frewin.
“Will you open it?” she said, “or shall I?”
Mrs. Frewin did not move. She stood as if turned to stone. Then
with dexterous fingers my lady broke the seals of the packet and
drew from it a few sheets of plain white cardboard and a thin piece of
match-boarding.
“There!” said Lady Molly, fingering the bits of cardboard while she
kept her fine large eyes fixed on Mrs. Frewin; “£200 is a big price to
pay for a sight of these worthless things.”
“Then this was a vulgar trick,” said Mrs. Frewin, drawing herself up
with an air which did not affect Lady Molly in the least.
“A trick, certainly,” she replied with her winning smile, “vulgar, if
you will call it so—pleasant to us all, Mrs. Frewin, since you so
readily fell into it.”
“Well, and what are you going to do next?”
“Report the matter to my chief,” said Lady Molly, quietly. “We have
all been very severely blamed for not discovering sooner the truth
about the disappearance of the Frewin miniatures.”
“You don’t know the truth now,” retorted Mrs. Frewin.
“Oh, yes, I do,” replied Lady Molly, still smiling. “I know that two
years ago your son, Mr. Lionel Frewin, was in terrible monetary
difficulties. There was something unavowable, which he dared not
tell his father. You had to set to work to find money somehow. You
had no capital at your own disposal, and you wished to save your
son from the terrible consequences of his own folly. It was soon after
M. de Colinville’s visit. Your husband had had his first apoplectic
seizure; his mind and eyesight were somewhat impaired. You are a
clever artist yourself, and you schemed out a plan whereby you
carefully copied the priceless miniatures and then entrusted them to
your son for sale to the Art Museum at Budapest, where there was
but little likelihood of their being seen by anyone who knew they had
belonged to your husband. English people do not stay more than
one night there, at the Hotel Hungaria. Your copies were works of art
in themselves, and you had no difficulty in deceiving your husband in
the state of mind he then was, but when he lay dying you realised
that his will would inevitably be proved, wherein he bequeathed the
miniatures to Mr. James Hyam, and that these would have to be
valued for probate. Frightened now that the substitution would be
discovered, you devised the clever comedy of the burglary at
Blatchley, which, in the circumstances, could never be brought home
to you or your son. I don’t know where you subsequently concealed
the spurious Engleheart miniatures which you calmly took out of the
library and hid away during the night of your husband’s death, but no
doubt our men will find that out,” she added quietly, “now that they
are on the track.”
With a frightened shriek Mrs. Frewin turned as if she would fly, but
Lady Molly was too quick for her, and barred the way. Then, with that
wonderful charm of manner and that innate kindliness which always
characterised her, she took hold of the unfortunate woman’s wrist.
“Let me give you a word of advice,” she said gently. “We at the
Yard will be quite content with a confession from you, which will clear
us of negligence and satisfy us that the crime has been brought
home to its perpetrator. After that try and enter into an arrangement
with your husband’s legatee, Mr. James Hyam. Make a clean breast
of the whole thing to him and offer him full monetary compensation.
For the sake of the family he won’t refuse. He would have nothing to
gain by bruiting the whole thing abroad; and for his own sake and
that of his late uncle, who was so good to him, I don’t think you
would find him hard to deal with.”
Mrs. Frewin paused awhile, undecided and still defiant. Then her
attitude softened; she turned and looked full at the beautiful, kind
eyes turned eagerly up to hers, and pressing Lady Molly’s tiny hand
in both her own she whispered:
“I will take your advice. God bless you.”
She was gone, and Lady Molly called Hankin to her side.
“Until we have that confession, Hankin,” she said, with the quiet
manner she always adopted where matters connected with her work
were concerned, “Mum’s the word.”
“Ay, and after that, too, my lady,” replied Hankin, earnestly.
You see, she could do anything she liked with the men, and I, of
course, was her slave.
Now we have got the confession, Mrs. Frewin is on the best of
terms with Mr. James Hyam, who has behaved very well about the
whole thing, and the public has forgotten all about the mystery of the
Frewin miniatures.
III.
THE IRISH-TWEED COAT

It all began with the murder of Mr. Andrew Carrthwaite, at Palermo.


He had been found dead in the garden of his villa just outside the
town, with a stiletto between his shoulder blades and a piece of
rough Irish tweed, obviously torn from his assailant’s coat, clutched
tightly in his hand.
All that was known of Mr. Carrthwaite over here was that he was a
Yorkshireman, owner of some marble works in Sicily, a man who
employed a great many hands; and that, unlike most employers of
labour over there, he had a perfect horror of the many secret
societies and Socialist clubs which abound in that part of the world.
He would not become a slave to the ever-growing tyranny of the
Mafia and its kindred associations, and therefore he made it a hard
and fast rule that no workman employed by him, from the foremost to
the meanest hand, should belong to any society, club, or trade union
of any sort or kind.
At first, robbery was thought to have been the sole object of the
crime, for Mr. Carrthwaite’s gold watch, marked with his initials
“A. C.,” and his chain were missing, but the Sicilian police were soon
inclined to the belief that this was merely a blind, and that personal
spite and revenge were at the bottom of that dastardly outrage.
One clue, remember, had remained in the possession of the
authorities. This was the piece of rough Irish tweed, found in the
murdered man’s hand.
Within twenty-four hours a dozen witnesses were prepared to
swear that that fragment of cloth was part of a coat habitually worn
by Mr. Carrthwaite’s English overseer, Mr. Cecil Shuttleworth. It
appears that this young man had lately, in defiance of the rigid rules
prescribed by his employer, joined a local society—semi-social,
semi-religious—which came under the ban of the old Yorkshireman’s
prejudices.
Apparently there had been several bitter quarrels between Mr.
Carrthwaite and young Shuttleworth, culminating in one tempestuous
scene, witnessed by the former’s servants at his villa; and although
these people did not understand the actual words that passed
between the two Englishmen, it was pretty clear that they amounted
to an ultimatum on the one side and defiance on the other. The
dismissal of the overseer followed immediately, and that same
evening Mr. Carrthwaite was found murdered in his garden.
Mind you—according to English ideas—the preliminary
investigations in that mysterious crime were hurried through in a
manner which we should think unfair to the accused. It seemed from
the first as if the Sicilian police had wilfully made up their minds that
Shuttleworth was guilty. For instance, although

“He had been found dead in the garden of his villa”


so many people were prepared to swear that the young English
overseer had often worn a coat of which the piece found in the
murdered man’s hand was undoubtedly a torn fragment, yet the coat
itself was not found among his effects, neither were his late master’s
watch and chain.
Nevertheless, the young man was arrested within a few hours of
the murder, and—after the formalities of the preliminary
“instruction”—was duly committed to stand his trial on the capital
charge.
It was about this time that I severed my official connection with the
Yard. Lady Molly now employed me as her private secretary, and I
was working with her one day in the study of our snug little flat in
Maida Vale, when our trim servant came in to us with a card and a
letter on a salver.
Lady Molly glanced at the card, then handed it across to me. It
bore the name: Mr. Jeremiah Shuttleworth.
The letter was from the chief.
“Not much in it,” she commented, glancing rapidly at its contents.
“The chief only says, ‘This is the father of the man who is charged
with the Palermo murder. As obstinate as a mule, but you have my
permission to do what he wants.’ Emily, show the gentleman in,” she
added.
The next moment a short, thick-set man entered our little study. He
had sandy hair and a freckled skin; there was a great look of
determination in the square face and a fund of dogged obstinacy in
the broad, somewhat heavy jaw. In response to Lady Molly’s
invitation he sat down and began with extraordinary abruptness:
“I suppose you know what I have come about—er—miss?” he
suggested.
“Well!” she replied, holding up his own card, “I can guess.”
“My son, miss—I mean ma’am,” he said in a husky voice. “He is
innocent. I swear it by the living——”
He checked himself, obviously ashamed of this outburst; then he
resumed more calmly.
“Of course, there’s the business about the coat, and that coat did
belong to my son, but——”
“Well, yes?” asked Lady Molly, for he had paused again, as if
waiting to be encouraged in his narrative, “what about that coat?”
“It has been found in London, miss,” he replied quietly. “The
fiendish brutes who committed the crime thought out this monstrous
way of diverting attention from themselves by getting hold of my
son’s coat and making the actual assassin wear it, in case he was
espied in the gloom.”
There was silence in the little study for awhile. I was amazed,
aghast at the suggestion put forward by that rough north-
countryman, that sorely stricken father who spoke with curious
intensity of language and of feeling. Lady Molly was the first to break
the solemn silence.
“What makes you think, Mr. Shuttleworth, that the assassination of
Mr. Carrthwaite was the work of a gang of murderers?” she asked.
“I know Sicily,” he replied simply. “My boy’s mother was a native of
Messina. The place is riddled with secret societies, murdering,
anarchical clubs: organisations against which Mr. Carrthwaite waged
deadly warfare. It is one of these—the Mafia, probably—that decreed
that Mr. Carrthwaite should be done away with. They could not do
with such a powerful and hard-headed enemy.”
“You may be right, Mr. Shuttleworth, but tell me more about the
coat.”
“Well, that’ll be damning proof against the blackguards, anyway. I
am on the eve of a second marriage, miss—ma’am,” continued the
man with seeming irrelevance. “The lady is a widow. Mrs. Tadworth
is her name—but her father was an Italian named Badeni, a
connection of my first wife’s, and that’s how I came to know him and
his daughter. You know Leather Lane, don’t you? It might be in Italy,
for Italian’s the only language one hears about there. Badeni owned
a house in Bread Street, Leather Lane, and let lodgings to his fellow-
countrymen there; this business my future wife still carries on. About
a week ago two men arrived at the house, father and son, so they
said, who wanted a cheap bedroom; all their meals, including
breakfast, they would take outside, and would be out, moreover,
most of the day.
“It seems that they had often lodged at Badeni’s before—the old
reprobate no doubt was one of their gang—and when they
understood that Mrs. Tadworth was their former friend’s daughter
they were quite satisfied.
“They gave their name as Piatti, and told Mrs. Tadworth that they
came from Turin. But I happened to hear them talking on the stairs,
and I knew that they were Sicilians, both of them.
“You may well imagine that just now everything hailing from Sicily
is of vital importance to me, and somehow I suspected those two
men from the very first. Mrs. Tadworth is quite at one with me in
wanting to move heaven and earth to prove the innocence of my
boy. She watched those people for me as a cat would watch a
mouse. The older man professed to be very fond of gardening, and
presently he obtained Mrs. Tadworth’s permission to busy himself in
the little strip of barren ground at the back of the house. This she told
me last night whilst we were having supper together in her little
parlour. Somehow I seemed to get an inspiration like. The Piattis had
gone out together as usual for their evening meal. I got a spade and
went out into the strip of garden. I worked for about an hour, and
then my heart gave one big leap—my spade had met a certain
curious, soft resistance—the next moment I was working away with
hands and nails, and soon unearthed a coat—the coat, miss,” he
continued, unable now to control his excitement, “with the bit torn out
of the back, and in the pocket the watch and chain belonging to the
murdered man, for they bear the initials ‘A. C.’ The fiendish brutes! I
knew it—I knew it, and now I can prove the innocence of my boy!”
Again there was a pause. I was too much absorbed in the
palpitating narrative to attempt to breathe a word, and I knew that
Lady Molly was placidly waiting until the man had somewhat
recovered from his vehement outburst.
“Of course, you can prove your boy’s innocence now,” she said,
smiling encouragingly into his flushed face. “But what have you done
with the coat?”
“Left it buried where I found it,” he replied more calmly. “They must
not suspect that I am on their track.”
She nodded approvingly.
“No doubt, then, my chief has told you that the best course to
pursue now will be to place the whole matter in the hands of the
English police. Our people at Scotland Yard will then immediately
communicate with the Sicilian authorities, and in the meanwhile we
can keep the two men in Leather Lane well under surveillance.”
“Yes, he told me all that,” said Mr. Shuttleworth, quietly.
“Well?”
“And I told him that his ‘communicating with the Sicilian police
authorities’ would result in my boy’s trial being summarily concluded,
in his being sent to the gallows, whilst every proof of his innocence
would be destroyed, or, at any rate, kept back until too late.”
“You are mad, Mr. Shuttleworth!” she ejaculated.
“Maybe I am,” he rejoined quietly. “You see, you do not know
Sicily, and I do. You do not know its many clubs and bands of
assassins, beside whom the so-called Russian Nihilists are simple,
blundering children. The Mafia, which is the parent of all such
murderous organisations, has members and agents in every town,
village, and hamlet in Italy, in every post-office and barracks, in every
trade and profession from the highest to the lowest in the land. The
Sicilian police force is infested with it, so are the Italian customs. I
would not trust either with what means my boy’s life and more to
me.”
“But——”
“The police would suppress the evidence connected with the
proofs which I hold. At the frontier the coat, the watch and chain
would disappear; of that I am as convinced as that I am a living man
——”
Lady Molly made no comment. She was meditating. That there
was truth in what the man said, no one could deny.
The few details which we had gleaned over here of the hurried
investigations, the summary commitment for trial of the accused, the
hasty dismissal of all evidence in his favour, proved that, at any rate,
the father’s anxiety was well founded.
“But, then, what in the world do you propose to
“ ‘Well,’ said Lady Molly, ‘… what is it that you want us to do in the
matter?’ ”

do?” said Lady Molly after a while. “Do you want to take the proofs
over yourself to your boy’s advocate? Is that it?”
“No, that would be no good,” he replied simply. “I am known in
Sicily. I should be watched, probably murdered, too, and my death
would not benefit my boy.”
“But what then?”
“My boy’s uncle is chief officer of police at Cividale, on the Austro-
Italian frontier. I know that I can rely on his devotion. Mrs. Tadworth,
whose interest in my boy is almost equal to my own, and whose
connection with me cannot possibly be known out there, will take the
proofs of my boy’s innocence to him. He will know what to do and
how to reach my son’s advocate safely, which no one else could
guarantee to do.”
“Well,” said Lady Molly, “that being so, what is it that you want us
to do in the matter?”
“I want a lady’s help, miss—er—ma’am,” he replied, “someone
who is able, willing, strong, and, if possible, enthusiastic, to
accompany Mrs. Tadworth—perhaps in the capacity of a maid—just
to avert the usual suspicious glances thrown at a lady travelling
alone. Also the question of foreign languages comes in. The
gentleman I saw at Scotland Yard said that if you cared to go he
would give you a fortnight’s leave of absence.”
“Yes, I’ll go!” rejoined Lady Molly, simply.
2

We sat in the study a long while after that—Mr. Shuttleworth, Lady


Molly and I—discussing the plans of the exciting journey; for I, too,
as you will see, was destined to play my small part in this drama
which had the life or death of an innocent man for its dénouement.
I don’t think I need bore you with an account of our discussion; all,
I think, that will interest you is the plan of campaign we finally
decided upon.
There seemed to be no doubt that Mr. Shuttleworth had
succeeded so far in not arousing the suspicions of the Piattis.
Therefore, that night, when they were safely out of the way, Mr.
Shuttleworth would once more unearth the coat, and watch and
chain, and then bury a coat quite similar in colour and texture in that
same hole in the ground; this might perhaps serve to put the
miscreants off their guard, if by any chance one of them should busy
himself again in the garden.
After that Mrs. Tadworth would hide about her the proofs of young
Shuttleworth’s innocence and join Lady Molly at our flat in Maida
Vale, where she would spend the night preparatory to the two ladies
leaving London for abroad, the following morning, by the 9.0 a.m.
train from Charing Cross en route for Vienna, Budapest, and finally
Cividale.
But our scheme was even more comprehensive than that, and
herein lay my own little share in it, of which I will tell you presently.
The same evening at half-past nine Mrs. Tadworth arrived at the
flat with the coat, and watch and chain, which were to be placed in
the hands of Colonel Grassi, the chief police officer at Cividale.
I took a keen look at the lady, you may be sure of that. It was a
pretty little face enough, and she herself could not have been much
more than seven or eight and twenty, but to me the whole
appearance and manner of the woman suggested weakness of
character, rather than that devotion on which poor Mr. Shuttleworth
so implicitly relied.
I suppose that it was on that account that I felt unaccountably
down-hearted and anxious when I bade farewell to my own dear lady
—a feeling in which she obviously did not share. Then I began to
enact the rôle which had been assigned to me.
I dressed up in Mrs. Tadworth’s clothes—we were about the same
height—and putting on her hat and closely fitting veil, I set out for
Leather Lane. For as many hours as I could possibly contrive to
keep up the deception, I was to impersonate Mrs. Tadworth in her
own house.
As I dare say you have guessed by now, that lady was not in
affluent circumstances, and the house in a small by-street off Leather
Lane did not boast of a staff of servants. In fact, Mrs. Tadworth did all
the domestic work herself, with the help of a charwoman for a couple
of hours in the mornings.
That charwoman had, in accordance with Lady Molly’s plan, been
given a week’s wages in lieu of notice. I—as Mrs. Tadworth—would
be supposed the next day to be confined to my room with a cold, and
Emily—our own little maid, a bright girl, who would go through fire
and water for Lady Molly or for me—would represent a new
charwoman.
As soon as anything occurred to arouse my suspicions that our
secret had been discovered, I was to wire to Lady Molly at the
various points which she gave me.
Thus provided with an important and comprehensive part, I duly
installed myself at Bread Street, Leather Lane. Emily—who had
been told just enough of the story, and no more, to make her eager,
excited and satisfied—entered into the spirit of her rôle as eagerly as
I did myself.
That first night was quite uneventful. The Piattis came home some
time after eleven and went straight up to their room.
Emily, looking as like a bedraggled charwoman as her trim figure
would allow, was in the hall the next morning when the two men
started off for breakfast. She told me afterwards that the younger
one looked at her very keenly, and asked her why the other servant
had gone. Emily replied with due and proper vagueness, whereupon
the Sicilians said no more and went out together.
That was a long and wearisome day which I spent cooped up in
the tiny, stuffy parlour, ceaselessly watching the tiny patch of ground
at the back, devoured with anxiety, following the travellers in my
mind on their way across Europe.
Towards midday one of the Piattis came home and presently
strolled out into the garden. Evidently the change of servants had
aroused his suspicions, for I could see him feeling about the earth
with his spade and looking up now and again towards the window of
the parlour, whereat I contrived to show him the form of a pseudo
Mrs. Tadworth moving about the room.
Mr. Shuttleworth and I were having supper in that same back
parlour at about nine o’clock on that memorable evening, when we
suddenly heard the front door being opened with a latchkey, and
then very cautiously shut again.
One of the two men had returned at an hour most unusual for their
otherwise very regular habits. The way, too, in which the door had
been opened and shut suggested a desire for secrecy and silence.
Instinctively I turned off the gas in the parlour, and with a quick
gesture pointed to the front room, the door of which stood open, and
I whispered hurriedly to Mr. Shuttleworth.
“Speak to him!”
Fortunately, the great aim which he had in view had rendered his
perceptions very keen.
He went into the front room, in which the gas, fortunately, was
alight at the time, and opening the door which gave thence on to the
passage, he said pleasantly:
“Oh, Mr. Piatti! is that you? Can I do anything for you?”
“Ah, yes! zank you,” replied the Sicilian, whose voice I could hear
was husky and unsteady, “if you would be so kind—I—I feel so
fainting and queer to-night—ze warm weazer, I zink. Would you—
would you be so kind to fetch me a little—er—ammoniac—er—sal
volatile you call it, I zink—from ze apothecary? I would go lie on my
bed—if you would be so kind——”
“Why, of course I will, Mr. Piatti,” said Mr. Shuttleworth, who
somehow got an intuition of what I wanted to do, and literally played
into my hands. “I’ll go at once.”
He went to get his hat from the rack in the hall whilst the Sicilian
murmured profuse “Zank you’s,” and then I heard the front door bang
to.
From where I was I could not see Piatti, but I imagined him
standing in the dimly-lighted passage listening to Mr. Shuttleworth’s
retreating footsteps.
Presently I heard him walking along towards the back door, and
soon I perceived something moving about in the little bit of ground
beyond. He had gone to get his spade. He meant to unearth the coat
and the watch and chain which, for some reason or another, he must
have thought were no longer safe in their original hiding-place. Had
the gang of murderers heard that the man who frequently visited
their landlady was the father of Cecil Shuttleworth over at Palermo?
At that moment I paused neither to speculate nor yet to plan. I ran
down to the kitchen, for I no longer wanted to watch Piatti. I knew
what he was doing.
I didn’t want to frighten Emily, and she had been made to
understand all along that she might have to leave the house with me
again at any time, at a moment’s notice; she and I had kept our small
handbag ready packed in the kitchen, whence we could reach the
area steps quickly and easily.
Now I quietly beckoned to her that the time had come. She took
the bag and followed me. Just as we shut the area gate behind us,
we heard the garden door violently slammed. Piatti had got the coat,
and by now was examining the pockets in order to find the watch
and chain. Within the next ten seconds he would realise that the coat
which he held was not the one which he had buried in the garden,
and that the real proofs of his guilt—or his complicity in the guilt of
another—had disappeared.
We did not wait for those ten seconds, but flew down Bread Street,
in the direction of Leather Lane, where I knew Mr. Shuttleworth
would be on the lookout for me.
“Yes,” I said hurriedly, directly I spied him at the angle of the street;
“it’s all up. I am off to Budapest by the early Continental to-morrow
morning. I shall catch them at the Hungaria. See Emily safely to the
flat.”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like