How to remember previous responses in Webhooks (Building Facebook Messenger Chat Bot) - heroku

For the chatbot, it is simple to implement a webhooks event for a single event such as:
If option A, send X
If option B, send Y
If Option C, send Z
However, what if the next event should be based off the previous event.
Such as there are options listed as:
A)
1
2
3
B)
1
2
3
Where you have to first send a letter, and then send a number. So if I want to choose B2, I have to send B, and then 2. However, it needs a way to remember the B choice. The way webhooks is implemented, the next message starts the program over so instead of the number, it would expect the letter again from the beginning.
If it was plain python, I would use the input() method after the first letter choice to wait for the number choice, but this method isn't an available option in webhooks as it breaks the program.
I would assume that there needs to be some sort of database for this, where letter choice is remembered and can then choose a number. I am running my webhooks through Heroku and would like insight for how this can be implemented if via database or if anyone can suggest a different method.

I can suggest you two options.
Option 1:
You can save your user's current state by using the PSID and option picked by user.
Option 2:
You can design your payloads in a ways so that you can identify your options. For example, when you are sending A) 1, 2, 3, you would actually send A1, A2, A3 in your payload, and 1, 2, 3 as viewing texts.

Related

How to send an email to subscribers?

I need inputs on how I can design a simple notification system .
There is system "Z" which generates certain events (this is an external system), and there are two systems A and B (internal systems) interested in getting email notifications about those events. However, A is interested in type "error" and B is interested in type "failure" of events from Z. I am trying to design system N which will translate those events from Z and send them as an email to A and B. I am not sure how many queues/topics I require.
Please let me know if the below steps are valid/needed/or can be improved
System A and B subscribe to emails. If I use a queue or topic the response from N has to be published on that topic, but I want to send out an email.
System N is listening to queue "test" on which system Z is publishing "error" and "failure" messages.
System N read and translates the messages from "test" queue and send email to subscribers i.e. A and B
I am mainly not sure of step 1. How will A and B let system N know that they need email notifications?
It sounds to me like you should deploy some kind of MLM (i.e. mailing list manager) which both systems A and B can use to subscribe to one or more relevant lists (e.g. an "error" list and/or a "failure" list). Then system N can send emails to those lists as needed when system Z generates the corresponding events.
Here is a list of well-known MLM implementations.

Twilio forwarding SMS to a different number and manage conversation

I want a user to send an SMS to a Twilio number. For simplicity, let's call the user phone number that sends an SMS "A" and the Twilio number "B". I want to add a little magic to the message, and then I want to forward the message to another phone number, let's call this phone number "C", that is associated with Twilio number "B".
A -> (B -> server) -> C.
When phone number "C" receives the message, it shows that it comes from phone number "B". However, I need it to show that the message was sent from phone number "A".
If this can be set up, I will also need to know how to make sure that if "C" sends a message that is intended for "A" that it will be forced to go to through the server and then be delivered to "A" showing that the number it was sent from is "B".
I'm sure that there is an easy fix, but I just can't seem to figure out how to make this happen. Any help would be much appreciated. Thanks.

Threaded group SMS conversations

I am trying to develop a web based SMS application and one of the features I would like to have is threaded group conversations.
Imagine there are 5 people, A, B, C, D, and E. 'A' is the person using the web application and 'B','C','D','E' are on their mobile phones.
I want to create two threads such as this:
A -> (B, C, D)
A -> (B, C, E)
And track those conversations so that person A can see a threaded conversation of those separate group chats.
One way that I know that I can do this is by using multiple twilio numbers but is there a way to do it without using multiple numbers? Is there a way to embed a key or ID in the messages that are sent/received? Twilio has cookie support but that seems to be limited to two person conversations and only works for conversations that are initiated outside the app.
I looked into Plivo and Nexmo but I don't think it's possible with them either.
Is this just a limitation of SMS or is it possible to do what I am trying to do?
SMS is stateless, and there's no way to tie two messages to each other (as a thread) other than match meta data (the pairing of a to / from).
For what you're trying to do, you'll need multiple virtual numbers, as this is limitation of SMS itself.

Internet Relay Chat rfc implementation

I am currently coding an Internet Relay Chat client/server implementation.
I read the RFC 1459 but some points are still unclear to me.
First let's say we have three users A, B and C.
A post a channel message, should I send it back to A, B and C or just B and C ? I mean should the client of A handle their own posting?
And the second point is, I would like to handle the possibility for the user to /join multiple channels.
How then could I handle the fact that my user can only post to one channel at a time? The RFC is unclear about it.
Regards, Swann
In the first sense no. Messages are not broadcast, so the user will not receive their own message back.
When sending a message you provide the destination. Whether that's a user or a channel. So PRIVMSG #channel :hello world will target that message to #channel. Other users in that room will receive the following:
:juco!~juco#hostname.com PRIVMSG #example :Hello world
This is explained in more details in 4.4.1 Private messages.

ZMQ patterns; send then receive

I have been reading up on zmq design patterns but I haven't seem to find that fits my need.
1. Box A sends info (json) to Box B and C; B and C gets different info from each other
2. Boxes B and C do some work based on info received from Box A
3. After finishing the work, Boxes B and C sends result back to Box A
Forwarder device (http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/devices/forwarder.html) can achieve step 1 and 2 but not 3, correct?
Are there any patterns I can use to achieve?
Is it simple request/reply pattern?
If so, is there a centralized request/reply pattern so that Box A doesnt pick Boxes B and C but rather Box A sends info to something central and it knows to send to Boxes B and C and send the result back to Box A?
This looks like a pretty basic Load Balancing pattern which is in the guide. A is the controller and will be a ROUTER, while the workers, B and C, are DEALERS. The messaging is simple enough; the dealers send an initial message to the controller to say "I'm ready". The controller then hands out work to the ready workers.
This topology is the opposite of Jason's answer. Which you choose just depends on how you're wanting to extend your application. When the controller hands out work, it really ought to go to a worker that is ready to handle it. With the Load Balancing pattern that is guaranteed.
This is a pretty basic DEALER/ROUTER pattern.
DEALER sockets are round-robin, which means it'll send one request to box B, then the next to box C, then the next to box B, etc. If you want to hold any work until the worker is completed, you just have to know the current count of available workers.
On box B and box C, use a ROUTER socket (or a REP socket if your use case is simple enough, but that'll limit your options). Receive the work, work on it, send it back, wait for more work.
There are many examples like this in the guide, which I recommend you read.

Resources