Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viber notificator #5097

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

merabtenei
Copy link
Contributor

I added a ViberNotificator based on the TelegramNotificator, it works the same way.
You need a bot API Key and a user unique ID obtained from webhook sent by viber (read viber documentation for details: https://developers.viber.com/docs/api/rest-bot-api/)
We tested this notificator and we are using it in our current project built on top of Traccar. We built an OTP system where we ask a user to send a code to our bot in order to get his/her viber_uid.
We are sharing this with the community in case you find this interesting.

Comment on lines 1169 to 1170
"notificator.viber.key",
List.of(KeyType.CONFIG));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What formatter are you using, because my Visual Studio code uses a different formatting and it changes formatting as soon as I save, I had to manually save without formatting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use IntelliJ.

/**
* Viber notification send location message.
*/
public static final ConfigKey<Boolean> NOTIFICATOR_VIBER_SEND_LOCATION = new BooleanConfigKey(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably unify this config parameter between telegram and viber.

Copy link
Contributor Author

@merabtenei merabtenei May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would we name this unified parameter ? Is NOTIFICATOR_SEND_LOCATION = "notificator.sendLocation" okey ?

Copy link
Contributor Author

@merabtenei merabtenei May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may keep this as it is for now to ensure backward compatibility, changing the parameter name would require modifications in traccar.xml when upgrading from an older version for anyone using this features. What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTIFICATOR_SEND_LOCATION = "notificator.sendLocation" sounds good to me. I think it's a rarely used key, so it's ok to break backward compatibility. Also, it doesn't really break notifications. You just won't get the location info.

Comment on lines 2 to 3
* Copyright 2019 - 2023 Anton Tananaev ([email protected])
* Copyright 2021 Rafael Miquelino ([email protected])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this. You can either put your name/email or keep mine, but the dates should be right.

Comment on lines 86 to 88
locationMessage.location = new LatLng();
locationMessage.location.latitude = position.getLatitude();
locationMessage.location.longitude = position.getLongitude();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
locationMessage.location = new LatLng();
locationMessage.location.latitude = position.getLatitude();
locationMessage.location.longitude = position.getLongitude();
LatLng latLng = new LatLng();
latLng.latitude = position.getLatitude();
latLng.longitude = position.getLongitude();
locationMessage.location = latLng;

private int minApiVersion = 1;
}

public static class LatLng {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably rename this to Location.

Comment on lines 102 to 103
client.target(urlSendText).request().header("X-Viber-Auth-Token",
config.getString(Keys.NOTIFICATOR_VIBER_KEY)).post(Entity.json(message)).close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should get the key once in the constructor and save it in a variable.

Also please reformat the request to something like:

Suggested change
client.target(urlSendText).request().header("X-Viber-Auth-Token",
config.getString(Keys.NOTIFICATOR_VIBER_KEY)).post(Entity.json(message)).close();
client.target(urlSendText).request()
.header("X-Viber-Auth-Token", ...)
.post(Entity.json(message))
.close();

Comment on lines 105 to 107
client.target(urlSendLocation).request().header("X-Viber-Auth-Token",
config.getString(Keys.NOTIFICATOR_VIBER_KEY)).post(
Entity.json(createLocationMessage(message.chatId, position)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@rkalman
Copy link

rkalman commented Dec 19, 2023

It is nice, but unfortunatelly a more interesting part is missing: getting viber uids from the viber webhook callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants