how to create keyboard in bot telegram - keyboard

enter image description here
help me to create keyboard (yes/no) for telegramBot (php)

I don't know PHP, but the tricky part is usually the keyboard part which is an array of arrays. Call sendMessage and pass something like the following json:
{
chat_id: 12345678,
text: "Hello, do you like ice cream?",
reply_markup: {
keyboard: [
[{text: "Yes"}],
[{text: "No"}]
]
}
}
Replace 12345678 with your chat id.

First get updates and save them into $update then for ReplyKeyboardMarkup use this method :
if ($update->message->text == '/start') {
$name = $update->message->chat->first_name;
bot('sendMessage',[
'chat_id' => $update->message->chat->id,
'text'=>'Your Test',
'resize_keyboard'=>true,
'reply_markup'=>json_encode([
'keyboard'=>[
[
['text'=>'Num1'],['text'=>'Num2']
],
[
['text'=>'Num2']
],
]
])
]);
}
and for inline keyboard you should use this method to send :
'reply_markup'=>json_encode([
'inline_keyboard'=>[
[
['text'=>'Num1'],['text'=>'Num2']
],
[
['text'=>'Num3']
],
]
])
]);
}
remember that bot function has 2 parameter that use curl for send and receive datas to telegram api.

Related

Gremlin - How to return a property of an edge alongside a node result?

I would like to know how to add to the result a property of the edge that links a node to another node
I'm using node.js to make queries to a Neptune database through Gremlin. Then I send the result to Javascript through an API.
let data = [];
const id_vertex = "1"
data = await g.V().has(id,id_vertex)
.out()
.valueMap()
.with_('~tinkerpop.valueMap.tokens'))
.toList();
This is how data looks like:
[
{
name: [ 'Colt Bogan II' ],
label: 'User',
notification: [ 'Both' ],
usercity: [ 'Wardburgh' ],
id: '1',
RegisteredDate: [ '2010-10-14' ]
},
{
name: [ 'Webster Sanford' ],
label: 'User',
notification: [ 'SMS' ],
usercity: [ 'Nanniefurt' ],
id: '2',
RegisteredDate: [ '2006-02-03' ]
}
]
Then I use JSON.stringify to make the body of what I send back to javascript
body: JSON.stringify(data)
"body":
"[{\"name\":[\"Colt Bogan II\"],\"label\":\"User\",\"notification\":[\"Both\"],\"usercity\":[\"Wardburgh\"],\"id\":\"1\",\"RegisteredDate\":[\"2010-10-14\"]},
{\"name\":[\"Webster Sanford\"],\"label\":\"User\",\"notification\":[\"SMS\"],\"usercity\":[\"Nanniefurt\"],\"id\":\"2\",\"RegisteredDate\":[\"2006-02-03\"]}]"
I would like to add the property of the edge that connects my node that has the id id_vertex to another node (when returning all the properties of that node) in the body. Either while I'm making the Gremlin query or after that. Let's say that the edge property I'm interested in is color, then in the end the body I would like to look like this:
"body":
"[{\"edgeColor\":[\"Green\"], \"name\":[\"Colt Bogan II\"],\"label\":\"User\",\"notification\":[\"Both\"],\"usercity\":[\"Wardburgh\"],\"id\":\"1\",\"RegisteredDate\":[\"2010-10-14\"]},
{\"edgeColor\":[\"Blue\"], \"name\":[\"Webster Sanford\"],\"label\":\"User\",\"notification\":[\"SMS\"],\"usercity\":[\"Nanniefurt\"],\"id\":\"2\",\"RegisteredDate\":[\"2006-02-03\"]}]"
Also, I have maximum one edge from one node to another, if this helps
If you modify your query slightly you can include edge properties in the result.
let data = [];
const id_vertex = "1"
data = await g.V().has(id,id_vertex)
.outE()
.project('edge','vertex')
.by(valueMap('edgeColor'))
.by(inV().valueMap().with_('~tinkerpop.valueMap.tokens'))
.toList();

How to trigger action from Chip Suggestions in Dialog Flow?

I want to create a ChatBot where the user (mostly) selects from Chip Suggestions.
I can't understand how to construct the Chip Suggestions in Flask.
The following yields null:
#app.route('/webhook', methods=['POST'])
def webhook():
two_chips = jsonify(fulfillment_text="This message is from Dialogflow's testing!",
fulfillment_messages=[
{
"payload": {
"richContent": [
[
{
"type": "chips",
"options": [
{
"text": "HIV Testing Schedule",
"link": "https://example.com" #Links work, but I don't want links
},
{
"link": "https://example.com",
"text": "PreP"
}
]
}
]
]
}
}])
return two_chips
Ideally, the button clicking would trigger a new action/intent and the bot would respond with more specific text. I.e. what should I replace the link field with?
This link suggests that there is a replyMetadata field, but that seems to be specific to kommunicate, not Google?
I looked flask-dialogflow, but the documentation is too sparse and conflicting for me.
Those chips which require a link, should be replaced by a list 1. List items are clickable and trigger an intent via events 2 (to make the bot respond with more specific text).
To get started, update your code to use lists and then add the event name you'd like to trigger in your code. Then add that same event name to the Events section of the intent you want to trigger.
Here is an example of what that can look like. I tested a list and clicked on a list item to triggered a test event that ran my test intent:
Are you looking for suggestion chips like the one below?
The sample payload that you have shared is from Kommunicate [Disclaimer: I am founder #kommunicate] and it is specific to Kommunicate platform for link buttons. Seems like what you are looking for is direct buttons/suggestion chips, here is the right doc from Kommunicate for this: https://docs.kommunicate.io/docs/message-types#suggested-replies
As Kommunicate supports omnichannel and multiple platforms web, android, iOS, whatsapp, LINE, facebook, etc so Kommunicate supports its own rich message payload along with Dialogflow specific payload.
For Dialogflow specific suggestion chips, use:
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "These are suggestion chips."
}
},
{
"simpleResponse": {
"textToSpeech": "Which type of response would you like to see next?"
}
}
],
"suggestions": [
{
"title": "Suggestion 1"
},
{
"title": "Suggestion 2"
},
{
"title": "Suggestion 3"
}
],
"linkOutSuggestion": {
"destinationName": "Suggestion Link",
"url": "https://assistant.google.com/"
}
}
}
}
}
Source: https://developers.google.com/assistant/conversational/df-asdk/rich-responses#df-json-suggestion-chips

Extract a list of profileId's using jsonpath

I have the following JSON object r2,
[
{
"reserva_id":"200",
"estancias":[
{
"reserva_estancia":"266",
"huespedes":[
{
"reserva_huesped":"272",
"reserva_estancia":"266",
"numero_huesped":"1",
"huesped":"123",
"huesped_nombre":"dos dos, dos",
"rfid":null
},
{
"reserva_huesped":"276",
"reserva_estancia":"266",
"numero_huesped":"2",
"huesped":"183",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
}
]
}
]
},
{
"reserva_id":"201",
"estancias":[
{
"huespedes":[
{
"reserva_huesped":"273",
"reserva_estancia":"267",
"numero_huesped":"1",
"huesped":"148",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
},
{
"reserva_huesped":"277",
"reserva_estancia":"267",
"numero_huesped":"2",
"huesped":"187",
"huesped_nombre":"TEST TEST, TESTCIVITFUN",
"rfid":null
}
]
}
]
}
]
I am trying to get the first huesped for each reservation, and for that I am using the following script, to create a list called profiles and store profileId's:
def profiles = jsonpath(r2,'$..[:].estancias[:].huespedes[0].huesped')
The output should be the following:
[
"123",
"148"
]
However, when I print profiles.text I get all the content of the estancias object, instead of just the huesped number.
When using Jayway's JSONPath like this I get the desired oputput:
$..[*].estancias[*].huespedes[0].huesped
You can try the path expression with your JSON here online.

restricting users on nodejs telegram bot

I currently have a telegram bot giving my organisation users answers to FAQ questions
but I need to restrict it so only certain people that have paid for the mentorship are able to use the product
is there anyway I can ask people to enter a user id number that stores the information
in so if there not on the list in the code there cant access the bot
my bot is currently written in nodejs language (based on this repo).
[
{
"triggers": [
"hello",
"hi"
],
"replies": [
{
"reply": "Hi Im your Personal Lion Bot \r\n\r\nWhat do you want to focus on today\r\n\r\n>Trading Help\r\n\r\n>Business Help\r\n\r\n>Mindset\r\n\r\n>Schedule\r\n\r\n>Just Started\r\n\r\n>Help",
"type": "text"
}
]
},
{
"triggers": [
"trading",
"Trading"
],
"replies": [
{
"reply": "Ok you want to focus on trading\r\n\r\nHeres is what I can show you\r\n\r\n>Our Schedule\r\n\r\n>A Trading Gameplan\r\n\r\n>Trade Ideas\r\n\r\n>Trading Products",
"type": "text"
}
]
}
]
You need to know your paying users' ID, then you answer their messages only if msg.from.id is in your list of allowed users.
Something like:
function check_if_allowed(id) {
...
}
bot.on('message', (msg) => {
if (check_if_allowed(msg.from.id)) {
...
}
})
To find their ID depends on how you register them in your organization.
Add more details and code if you need further help

Adaptive Cards and Microsoft Bot Framework: will only permit 'openUrl' action?

EDIT 2: The following schema (provided by a colleague) works. I removed the quotation marks from the schema in the examples from Microsoft, but that still didn't work. I'm not sure what the issue is. I leave the question open in case someone else wants to provide an answer, but I've got it working.
const card = {
contentType: 'application/vnd.microsoft.card.adaptive',
content: {
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
type: 'AdaptiveCard',
version: '1.0',
{
type: 'Input.Text',
placeholder: 'Name',
style: 'text',
maxLength: 50,
id: 'defaultInput'
},
actions: [
{
type: 'Action.Submit',
title: 'Siguiente',
data: {} // will be populated with form input values
}
]
}
};
I'm trying to make a form in my MS Bot using Adaptive Cards. I took the sample form from the MS site (https://blog.botframework.com/2019/07/02/using-adaptive-cards-with-the-microsoft-bot-framework/) but get the following error
The error seems to be thinking that my action type is Action.openUrl but I don't see that in my code, which is below. Any help much appreciated. Using Microsoft Bot Framework 3, Node 12.13.0.
function askPolicyNumber(session) {
const card = {
'$schema': 'https://adaptivecards.io/schemas/adaptive-card.json',
'type': 'AdaptiveCard',
'version': '1.1',
'body': [
{
'type': 'Input.Text',
'id': 'id_text'
},
{
'type': 'Input.Number',
'id': 'id_number'
}
],
'actions': [
{
'type': 'Action.messageBack',
'title': 'Submit',
'data': {
'prop1': true,
'prop2': []
}
}
]
};
const msg = new builder.Message(session).attachments([card]);
return session.send(msg);
}
EDIT:
It seems that no matter what I set the action to it keeps thinking it's an openUrl action. In fact, if I set it to openUrl and give it a url property, it works fine.
I looked at this page -- https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-actions#adaptive-cards-actions -- and followed the instructions there for 'Adaptive Cards with messageBack action', but it didn't change anything
"actions": [
{
"type": "Action.Submit",
"title": "Click me for messageBack",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "I clicked this button",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
There are a lot of problems with what you're doing. It is recommended that everyone use Bot Builder v4 instead of v3. The main problem that your colleague solved was that you were trying to use an Adaptive Card object as though it was an Attachment object.
The blog post you linked to explains that Adaptive Cards must follow the Adaptive Cards schema. There is no Action.messageBack in the Adaptive Cards schema. Please continue referring to the documentation for more information.

Resources