Code Monkey home page Code Monkey logo

signal-bot's Introduction

signal-bot

This is a simple bot system for Signal with minimal dependencies. Pure Java and cross platform.

Prerequisites

  • JDK 11+ due to TLS v3 requirement. A newer JDK version should work but it's untested. You can get an installer from AdoptOpenJDK.
  • A phone number you can receive SMS messages or voice calls on. You'll need to dedicate that number to the bot.

Building

gradlew installDist should generate a run script at 'build/install/signal-bot/bin/signal-bot'.

Running

  1. To register the bot on the Signal service, run signal-bot --register-text +12223334444 (change the phone number to any number that you can receive an SMS on.)
    • To get the verification code using a voice call instead, replace register-text with register-voice.
  2. After receiving the verification SMS, run signal-bot --verify 123-456 (change the number to the code you received.)
  3. To start the bot, run signal-bot --listen. You should be able to then message the bot and see your messages in the log.
    • Note: it might take a few minutes for the bot to be properly registered with the Signal server and be able to receive messages.
  4. To stop the bot, interrupt with Ctrl+C or kill -2 to allow it to shut down and disconnect gracefully from the Signal service.
  5. To dry-run test the listener, use signal-bot --test. This will start a simple input loop that sends your messages to the bot and sends the response to stdout. This doesn't use the Signal service.

Adding new message responders

  1. Create a new class that implements SignalBot.Responder. For example, this will echo back every message received:
package com.woodencloset.signalbot.responders;

import com.woodencloset.signalbot.SignalBot;

public class EchoResponder implements SignalBot.Responder {
    @Override
    public String getResponse(String messageText) {
        return messageText;
    }
}
  1. Add the line bot.addResponder(new EchoResponder()); to the Main class (as an example, there is a DiceRollResponder included and added already.)

Limitations

  • For code simplicity, keys are stored in-memory, so it's mostly suitable for a long running session on a server. If you terminate and re-run, all keys (including identity key) will be re-generated which would necessitate other parties to re-approve the bot's identity.
  • Group info is stored in-memory as well. If you join a group and then re-run the bot, the first message in the group will be ignored as the bot updates its internal group info. This could be solved by using a message queue, but that's currently not implemented, for code simplicity.
  • Bot interface only supports receiving and sending simple text responses. No images or other data. Messages are always sent back to the sender, or to the group, if sent from one.
  • Only legacy groups are currently supported. Supports for new groups is WIP.

signal-bot's People

Contributors

aaronetz avatar albjeremias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

signal-bot's Issues

Save keys (don't generate new IdentityKeyPair every time)

Is your feature request related to a problem? Please describe.
It would be great if the KeyPair is not regenerated at every startup, but is saved so that the contact does not have to be reconfirmed every time in Signal.

Describe the solution you'd like
Keys shuld be saved

Additional context
I've already tried to do it by myself, but it looks like I used the wrong approach. I'm using the following approach:
Check if KeyPair.txt exists
if not exists -> Generate KeyPair, serialize it and save it to KeyPair.txt
if exists -> Deserialize key from KeyPair.txt
After that refresh the pre keys.
At the first start everything works without problems. But when I stop it and start it again, it doesn't work anymore. I always get the following error when I try to write a message to the bot: "Error processing message: org.signal.libsignal.metadata.ProtocolNoSessionException: org.whispersystems.libsignal.NoSessionException: No session for: :1".
It doesn't matter where I put the refreshPreKeys, or if I leave it out altogether.

Runnning program

How exactly do you send and receive messages? Do you open a new terminal? I verified successfully and can listen. But then what? I tried sending myself text messages seeing if they appear but to no avail.

And on Signal, my phone de-registers when I register from the terminal so I can't even send notes to myself.

Thanks!

Bot responds to PM even if message sent in group

Describe the bug
The bot responds in private messages even if command is sent in group

To Reproduce
Steps to reproduce the behavior:

  1. Send message to bot in group
  2. Bot responds in private message

Expected behavior
Bot sends response to group

Captcha request not working / need help

Describe the bug
I've tried your signal bot today. If I start it with "--register-voice +XXXXXXXXXX", I get an "org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException". So I've tried to use the provided URL to generate a captcha code, but it seems not to be possible. If I open the link on my computer, it tried to open an "signalcaptcha://"-link, which is not possible. If I open the page on my mobile phone, it tells me that the URL is invalid. What do I have to do to generate a captcha?

To Reproduce

  1. Open the URL https://signalcaptchas.org/registration/generate.html
  2. Try to generate a captcha

Expected behavior
A captcha should be generated

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Firefox
  • Version 94.0.1

Smartphone (please complete the following information):

  • Device: iPhone 12
  • OS: iOS 15.1
  • Browser Safari
  • Version ---

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.