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

start interactive game by direct link #1707

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions interactive/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ def serve(self, request, *args, **kwargs):

if not user:
return redirect("/")

if request.method == "GET":
chat = Message.objects.filter(to=user).order_by("-created_at").first()
if not chat:
self.send_message_to_rapidpro(user=user, text=self.trigger_string)

if request.method == "POST":
form = MessageSendForm(request.POST)

if form.is_valid():
channel_url = self.channel.request_url

data = {"from": user, "text": form.cleaned_data["text"]}

try:
response = requests.post(url=channel_url, data=data)
response.raise_for_status()
except requests.exceptions.RequestException:
return redirect("/")
self.send_message_to_rapidpro(user=user, text=form.cleaned_data["text"])

return redirect(self.get_url(request))

Expand Down Expand Up @@ -165,5 +162,13 @@ def send_message_on_language_switch(self, request, user):
referer_lang = current_lang

if referer_lang != current_lang:
data = {"from": user, "text": self.trigger_string}
requests.post(url=self.channel.request_url, data=data)
self.send_message_to_rapidpro(user=user, text=self.trigger_string)

def send_message_to_rapidpro(self, user, text):
data = {"from": user, "text": text}

try:
response = requests.post(url=self.channel.request_url, data=data)
response.raise_for_status()
except requests.exceptions.RequestException as e:
return redirect("/")
Loading