simplebot-org / simplebot

Extensible Delta Chat bot written in Python3
Mozilla Public License 2.0
34 stars 9 forks source link

Custom server configurations #63

Closed genya1 closed 2 years ago

genya1 commented 3 years ago

I was having difficulties setting up this bot because the email server I use requires custom port, hostname, and security. To ease the setup process, could we introduce a config file during the init process ?

adbenitez commented 3 years ago

hello @genya1, sorry for the late reply (to your initial issue), I have just added more options to the command line, now you can set bot avatar, display name and also low level configurations if your server needs special configuration, for that you can use the command: simplebot set_config

adbenitez commented 3 years ago

and please consider to add your server to https://github.com/deltachat/provider-db (if it is a public server) so your users don't have to configure anything manually

adbenitez commented 3 years ago

solved via https://github.com/SimpleBot-Inc/simplebot/commit/5e696b66517a6f64442fa5b6cb34e833d4837455

genya1 commented 3 years ago

Thank you

genya1 commented 3 years ago

Hello @adbenitez, I am trying to use simplebot set_config to set the special configurations for my email server (it is not public). Some example special configurations I would like to set are mail_port and mail_security referencing the deltachat-core-rust config. I am not able to set them because I need to have a default account setup, but I cannot have a default account setup without those configurations, can you please re-open this issue and would it be possible to set the special configurations before a default account exists ?

adbenitez commented 3 years ago

for now this is what you can do:

  1. execute simplebot init foo@example.com Password
  2. it will fail, but now you can do simplebot set_config set the appropriate settings
  3. execute simplebot init foo@example.com Password again

@genya1 in the future I could add some options to init so you can do something like:

simplebot init --mail_port=143  foo@example.com Password123

but for now use the above hack and consider adding your provider to https://providers.delta.chat/ so there is no need for extra configurations

genya1 commented 3 years ago

I tried that above it did not work unfortunately, #1 does not output anything to console it is just stuck in re-try loop from looking at how deltachat-core-rust works. The only way I have been able to go around this is hard-code in the code the special configurations. And I am sorry I can add my email server to the provider because it is not public.

adbenitez commented 3 years ago

@genya1 mmh... true, you commented about the blocking issue before, then I will need to add the options to tweak configuration in simplebot init

adbenitez commented 3 years ago

try this hack in the meantime (given your bot address is bot@example.com):

simplebot -a ~/.config/simplebot/bot%40example.com set_config mail_port 143 

when you are done configuring:

simplebot init  bot@example.com PASSWORD
adbenitez commented 3 years ago

for now this is what you can do:

1. execute `simplebot init foo@example.com Password`

2. it will fail, but now you can do `simplebot set_config` set the appropriate settings

3. execute  `simplebot init foo@example.com Password` again

@genya1 in the future I could add some options to init so you can do something like:

simplebot init --mail_port=143  foo@example.com Password123

but for now use the above hack and consider adding your provider to https://providers.delta.chat/ so there is no need for extra configurations

thinking about it better, even if the process of simplebot init get stuck you should be able to cancel it with ctrl+c then follow the next steps, this is all a hack, we need to add the options to init so it is easy to do

genya1 commented 3 years ago

Got it working with setting all the configurations using simplebot -a ~/.config/simplebot/bot%40example.com set_config. Thanks! And yeah I like the idea of doing it like simplebot init --mail_port=143 foo@example.com Password123, but just curious what is your opinion on making the user have a config file for each account if they want custom configurations ?

I think having a config file might overcomplicate the onboarding process and add another workflow to set the settings, but with a config file it is a one pass to set everything up whereas using the command line for each configuration is cumbersome. What are your thoughts ?

adbenitez commented 3 years ago

the account email configurations only need to be set once when initializing the account the first time with init, so it doesn't makes much sense, IMHO, to save them in a file, storing passwords etc.

"the config file" equivalent here is the account database which is an sqlite database and you use set_config to write to that "config file" directly, otherwise we will need to have settings duplicated in two places and serveral ways to change them and having to worry about synchronization, so I don't think I will add a config file for account settings

genya1 commented 3 years ago

I think that is fair, thanks for explaining

sysfu commented 9 months ago

Hello @adbenitez, I am trying to use simplebot set_config to set the special configurations for my email server (it is not public). Some example special configurations I would like to set are mail_port and mail_security referencing the deltachat-core-rust config. I am not able to set them because I need to have a default account setup, but I cannot have a default account setup without those configurations, can you please re-open this issue and would it be possible to set the special configurations before a default account exists ?

If anyone viewing this ticket is searching for a place where all the special configuration options are documented, I found them here at https://github.com/deltachat/deltachat-core-rust/blob/b779d08d7f7d02d7b9570e4b0cf87ccc2e255517/deltachat-ffi/deltachat.h#L396

* - `addr`         = Email address to use for configuration.
 *                    If dc_configure() fails this is not the email address actually in use.
 *                    Use `configured_addr` to find out the email address actually in use.
 * - `configured_addr` = Email address actually in use.
 *                    Unless for testing, do not set this value using dc_set_config().
 *                    Instead, set `addr` and call dc_configure().
 * - `mail_server`  = IMAP-server, guessed if left out
 * - `mail_user`    = IMAP-username, guessed if left out
 * - `mail_pw`      = IMAP-password (always needed)
 * - `mail_port`    = IMAP-port, guessed if left out
 * - `mail_security`= IMAP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
 * - `send_server`  = SMTP-server, guessed if left out
 * - `send_user`    = SMTP-user, guessed if left out
 * - `send_pw`      = SMTP-password, guessed if left out
 * - `send_port`    = SMTP-port, guessed if left out
 * - `send_security`= SMTP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
 * - `server_flags` = IMAP-/SMTP-flags as a combination of @ref DC_LP flags, guessed if left out
 * - `socks5_enabled` = SOCKS5 enabled
 * - `socks5_host` = SOCKS5 proxy server host
 * - `socks5_port` = SOCKS5 proxy server port
 * - `socks5_user` = SOCKS5 proxy username
 * - `socks5_password` = SOCKS5 proxy password
 * - `imap_certificate_checks` = how to check IMAP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
 * - `smtp_certificate_checks` = how to check SMTP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
 * - `displayname`  = Own name to use when sending messages. MUAs are allowed to spread this way e.g. using CC, defaults to empty
 * - `selfstatus`   = Own status to display, e.g. in e-mail footers, defaults to empty
 * - `selfavatar`   = File containing avatar. Will immediately be copied to the 
 *                    `blobdir`; the original image will not be needed anymore.
 *                    NULL to remove the avatar.
 *                    As for `displayname` and `selfstatus`, also the avatar is sent to the recipients.
 *                    To save traffic, however, the avatar is attached only as needed
 *                    and also recoded to a reasonable size.
 * - `e2ee_enabled` = 0=no end-to-end-encryption, 1=prefer end-to-end-encryption (default)
 * - `mdns_enabled` = 0=do not send or request read receipts,
 *                    1=send and request read receipts (default)
 * - `bcc_self`     = 0=do not send a copy of outgoing messages to self (default),
 *                    1=send a copy of outgoing messages to self.
 *                    Sending messages to self is needed for a proper multi-account setup,
 *                    however, on the other hand, may lead to unwanted notifications in non-delta clients.
 * - `sentbox_watch`= 1=watch `Sent`-folder for changes,
 *                    0=do not watch the `Sent`-folder (default),
 *                    changes require restarting IO by calling dc_stop_io() and then dc_start_io().
 * - `mvbox_move`   = 1=detect chat messages,
 *                    move them to the `DeltaChat` folder,
 *                    and watch the `DeltaChat` folder for updates (default),
 *                    0=do not move chat-messages
 *                    changes require restarting IO by calling dc_stop_io() and then dc_start_io().
 * - `only_fetch_mvbox` = 1=Do not fetch messages from folders other than the
 *                    `DeltaChat` folder. Messages will still be fetched from the
 *                    spam folder and `sendbox_watch` will also still be respected
 *                    if enabled.
 *                    0=watch all folders normally (default)
 *                    changes require restarting IO by calling dc_stop_io() and then dc_start_io().
 * - `show_emails`  = DC_SHOW_EMAILS_OFF (0)=
 *                    show direct replies to chats only,
 *                    DC_SHOW_EMAILS_ACCEPTED_CONTACTS (1)=
 *                    also show all mails of confirmed contacts,
 *                    DC_SHOW_EMAILS_ALL (2)=
 *                    also show mails of unconfirmed contacts (default).
 * - `key_gen_type` = DC_KEY_GEN_DEFAULT (0)=
 *                    generate recommended key type (default),
 *                    DC_KEY_GEN_RSA2048 (1)=
 *                    generate RSA 2048 keypair
 *                    DC_KEY_GEN_ED25519 (2)=
 *                    generate Curve25519 keypair
 *                    DC_KEY_GEN_RSA4096 (3)=
 *                    generate RSA 4096 keypair
 * - `save_mime_headers` = 1=save mime headers
 *                    and make dc_get_mime_headers() work for subsequent calls,
 *                    0=do not save mime headers (default)
 * - `delete_device_after` = 0=do not delete messages from device automatically (default),
 *                    >=1=seconds, after which messages are deleted automatically from the device.
 *                    Messages in the "saved messages" chat (see dc_chat_is_self_talk()) are skipped.
 *                    Messages are deleted whether they were seen or not, the UI should clearly point that out.
 *                    See also dc_estimate_deletion_cnt().
 * - `delete_server_after` = 0=do not delete messages from server automatically (default),
 *                    1=delete messages directly after receiving from server, mvbox is skipped.
 *                    >1=seconds, after which messages are deleted automatically from the server, mvbox is used as defined.
 *                    "Saved messages" are deleted from the server as well as
 *                    e-mails matching the `show_emails` settings above, the UI should clearly point that out.
 *                    See also dc_estimate_deletion_cnt().
 * - `media_quality` = DC_MEDIA_QUALITY_BALANCED (0) =
 *                    good outgoing images/videos/voice quality at reasonable sizes (default)
 *                    DC_MEDIA_QUALITY_WORSE (1)
 *                    allow worse images/videos/voice quality to gain smaller sizes,
 *                    suitable for providers or areas known to have a bad connection.
 *                    The library uses the `media_quality` setting to use different defaults
 *                    for recoding images sent with type #DC_MSG_IMAGE.
 *                    If needed, recoding other file types is up to the UI.
 * - `webrtc_instance` = webrtc instance to use for videochats in the form
 *                    `[basicwebrtc:|jitsi:]https://example.com/subdir#roomname=$ROOM`
 *                    if the URL is prefixed by `basicwebrtc`, the server is assumed to be of the type
 *                    https://github.com/cracker0dks/basicwebrtc which some UIs have native support for.
 *                    The type `jitsi:` may be handled by external apps.
 *                    If no type is prefixed, the videochat is handled completely in a browser.
 * - `bot`          = Set to "1" if this is a bot.
 *                    Prevents adding the "Device messages" and "Saved messages" chats,
 *                    adds Auto-Submitted header to outgoing messages,
 *                    accepts contact requests automatically (calling dc_accept_chat() is not needed for bots)
 *                    and does not cut large incoming text messages.
 * - `last_msg_id` = database ID of the last message processed by the bot.
 *                   This ID and IDs below it are guaranteed not to be returned
 *                   by dc_get_next_msgs() and dc_wait_next_msgs().
 *                   The value is updated automatically
 *                   when dc_markseen_msgs() is called,
 *                   but the bot can also set it manually if it processed
 *                   the message but does not want to mark it as seen.
 *                   For most bots calling `dc_markseen_msgs()` is the
 *                   recommended way to update this value
 *                   even for self-sent messages.
 * - `fetch_existing_msgs` = 1=fetch most recent existing messages on configure (default),
 *                    0=do not fetch existing messages on configure.
 *                    In both cases, existing recipients are added to the contact database.
 * - `disable_idle` = 1=disable IMAP IDLE even if the server supports it,
 *                    0=use IMAP IDLE if the server supports it.
 *                    This is a developer option used for testing polling used as an IDLE fallback.
 * - `download_limit` = Messages up to this number of bytes are downloaded automatically.
 *                    For larger messages, only the header is downloaded and a placeholder is shown.
 *                    These messages can be downloaded fully using dc_download_full_msg() later.
 *                    The limit is compared against raw message sizes, including headers.
 *                    The actually used limit may be corrected
 *                    to not mess up with non-delivery-reports or read-receipts.
 *                    0=no limit (default).
 *                    Changes affect future messages only.
 * - `gossip_period` = How often to gossip Autocrypt keys in chats with multiple recipients, in
 *                    seconds. 2 days by default.
 *                    This is not supposed to be changed by UIs and only used for testing.
 * - `verified_one_on_one_chats` = Feature flag for verified 1:1 chats; the UI should set it
 *                    to 1 if it supports verified 1:1 chats.
 *                    Regardless of this setting, `dc_chat_is_protected()` returns true while the key is verified,
 *                    and when the key changes, an info message is posted into the chat.
 *                    0=Nothing else happens when the key changes.
 *                    1=After the key changed, `dc_chat_can_send()` returns false and `dc_chat_is_protection_broken()` returns true
 *                    until `dc_accept_chat()` is called.
 * - `ui.*`         = All keys prefixed by `ui.` can be used by the user-interfaces for system-specific purposes.
 *                    The prefix should be followed by the system and maybe subsystem,
 *                    e.g. `ui.desktop.foo`, `ui.desktop.linux.bar`, `ui.android.foo`, `ui.dc40.bar`, `ui.bot.simplebot.baz`.
 *                    These keys go to backups and allow easy per-account settings when using @ref dc_accounts_t,
 *                    however, are not