Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ZAKI RAIHAN
1606878505_ossd_telegram_notif_bot
Commits
1efc3aeb
Commit
1efc3aeb
authored
Oct 04, 2019
by
zakiraihan
Browse files
Applying send notification function
parent
768cdfc6
Changes
3
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
1efc3aeb
...
...
@@ -47,15 +47,18 @@ def hello():
@
app
.
route
(
'/sendNotification'
,
methods
=
[
'POST'
])
def
sendNotif
():
from
models.
User
Model
import
User
Model
from
models.
Account
Model
import
Account
Model
req_data
=
request
.
get_json
()
user
=
User
Model
.
query
.
filter
(
UserModel
.
phoneNumber
==
req_data
[
'
phoneNumber
'
]).
first
()
user
=
Account
Model
.
query
.
filter
(
AccountModel
.
ssoId
==
req_data
[
'
username
'
]).
first
()
if
(
user
is
None
):
return
{
'status'
:
404
,
'message'
:
'User not found'
}
param
=
urllib
.
parse
.
urlencode
({
'chat_id'
:
user
.
userId
,
'text'
:
req_data
[
'message'
]})
url
=
"https://api.telegram.org/bot"
+
TOKEN
+
"/sendMessage?"
+
param
r
=
requests
.
get
(
url
=
url
)
return
r
.
json
()
elif
(
user
.
chatId
==
None
):
return
{
'status'
:
500
,
'message'
:
'User notification is being turned off'
}
else
:
param
=
urllib
.
parse
.
urlencode
({
'chat_id'
:
user
.
chatId
,
'text'
:
req_data
[
'message'
]})
url
=
"https://api.telegram.org/bot"
+
TOKEN
+
"/sendMessage?"
+
param
r
=
requests
.
get
(
url
=
url
)
return
r
.
json
()
@
app
.
route
(
"/auth/"
,
methods
=
[
'POST'
])
def
auth
():
...
...
navigation/navigation.py
View file @
1efc3aeb
...
...
@@ -14,7 +14,7 @@ def botNavigation(bot, update):
elif
(
text
==
"/activateNotif"
):
user_activate_notif
(
bot
,
chat_id
)
elif
(
text
==
None
and
contact
!=
None
)
:
save_user_data
(
bot
,
chat_id
,
contact
)
save_user_
notif_activation_
data
(
bot
,
chat_id
,
contact
)
elif
(
text
==
"/deactivateNotif"
):
user_deactive_notif
(
bot
,
chat_id
)
elif
(
text
==
"/login"
):
...
...
telebot/mastermind.py
View file @
1efc3aeb
...
...
@@ -26,7 +26,7 @@ def user_activate_notif(bot, chat_id):
text
=
"Would you mind sharing your contact with me?"
,
reply_markup
=
reply_markup
)
else
:
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"You
have been registered
"
,
reply_markup
=
ReplyKeyboardRemove
())
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"You
r notification is still active
"
,
reply_markup
=
ReplyKeyboardRemove
())
def
save_user_notif_activation_data
(
bot
,
chat_id
,
contact
):
checkAccountExistance
=
AccountModel
.
query
.
filter
(
AccountModel
.
phoneNumber
==
str
(
contact
.
phone_number
)).
first
()
...
...
@@ -38,13 +38,13 @@ def save_user_notif_activation_data(bot, chat_id, contact):
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"Register success!!!"
,
reply_markup
=
ReplyKeyboardRemove
())
def
user_deactive_notif
(
bot
,
chat_id
):
check
User
Existance
=
User
Model
.
query
.
filter
(
User
Model
.
user
Id
==
str
(
chat_id
)).
first
()
if
(
check
User
Existance
is
None
):
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"You are not
registerd
yet"
,
reply_markup
=
ReplyKeyboardRemove
())
check
Account
Existance
=
Account
Model
.
query
.
filter
(
Account
Model
.
chat
Id
==
str
(
chat_id
)).
first
()
if
(
check
Account
Existance
is
None
):
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"You are not
activating your notification
yet"
,
reply_markup
=
ReplyKeyboardRemove
())
else
:
check
User
Existance
=
UserModel
.
query
.
filter
(
UserModel
.
userId
==
str
(
chat_id
)).
first
()
check
User
Existance
.
dele
te
()
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"Successfully
logged out from bot
"
,
reply_markup
=
ReplyKeyboardRemove
())
check
Account
Existance
.
chatId
=
None
check
Account
Existance
.
upda
te
()
bot
.
sendMessage
(
chat_id
=
chat_id
,
text
=
"Successfully
turning off your notification
"
,
reply_markup
=
ReplyKeyboardRemove
())
def
user_login_sso
(
bot
,
chat_id
):
base_url
=
os
.
environ
.
get
(
'URL'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment