Comments (3)
I'm not entirely sure what you are trying to accomplish by using sessions, but I came up with a solution using User State in the BotFramework that might work for you.
Right below where the memory is initialized in the main.py file, uncomment user_state = UserState(memory)
. It should be on line 32 in the Rich-Cards-Bot example, but it might be further down since I believe you've imported a few packages. You also need to uncomment ADAPTER.use(user_state)
on line 35.
Then in the handle_message
function, you can either access the User_code
from the user_state
or create a new User_code
in the user_state
if it doesn't exist. Your code should look something like this:
# Create MemoryStorage, UserState and ConversationState
memory = MemoryStorage()
user_state = UserState(memory)
...
# Register both State middleware on the adapter.
ADAPTER.use(user_state)
ADAPTER.use(conversation_state)
...
async def handle_message(context: TurnContext) -> web.Response:
# Access the state of the user
user = await user_state.get(context)
if not hasattr(user, 'User_code'):
user.User_code = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])
print(user.User_code)
...
return web.Response(status=202)
...
async def messages(req: web.web_request) -> web.Response:
body = await req.json()
activity = Activity().deserialize(body)
auth_header = req.headers['Authorization'] if 'Authorization' in req.headers else ''
try:
return await ADAPTER.process_activity(activity, auth_header, request_handler)
except Exception as e:
raise e
app = web.Application()
app.router.add_post('/', messages)
try:
web.run_app(app, host='localhost', port=PORT)
except Exception as e:
raise e
Using the user state, the User_code
stays consistent between messages, and the output looks like this:
User_code: BGjvg9FkUCJeUoOa
User_code: BGjvg9FkUCJeUoOa
User_code: BGjvg9FkUCJeUoOa
If this solution doesn't work for what you are trying to do, please let me know and I will look deeper into the issue you are having with sessions.
from botbuilder-python.
Thanks for your reply @tdurnford. simply this is what i want. so.... by using this, we could save user information right? and its for multi user that's all. Thanks alot! and i think this is what @varunreddycs asked for state data. if we have example code with this it will be better for the starter. if you don't mind i would like to ask one thing more that how can i use adaptive_card button data as an input? example i have a Card with button value yes or no. on javascript or c# botframework i could see their value can be in the chat text, or as input value. i'm waiting for you great answer :)
from botbuilder-python.
Yes, you can store user information such as name and id in the user state and the data will be preserved for each user between conversations.
In regards to your second question, the Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repos are the preferred platform for submitting bug fixes and feature requests. However, if you send me the link for your question on Stack Overflow, I will gladly take a look at it.
from botbuilder-python.
Related Issues (20)
- Extensibility for Teams AI - ability to add to User Agent for Teams AI telemetry HOT 1
- Internal bot on SDK v4 does not work with New Teams HOT 3
- CloudAdapter.continue_conversation() is missing `bot_app_id` parameter
- 4.14.6 CloudAdapter fails to send Typing Activity in Teams HOT 4
- Support Single Tenant AppType HOT 5
- Update the dependency azure-cosmos > 3.2. HOT 5
- port: CertificateServiceClientCredentialsFactory
- Ability to pass BotFrameworkConnectorConfiguration into ConfigurationBotFrameworkAuthentication
- Add AllowedCallersClaimsValidator, AllowedSkillsClaimsValidator
- ESRP in build pipelines HOT 1
- aiohttp.web_exceptions.HTTPNotFound: Not Found HOT 7
- Recommended change to 3.8.6 or above HOT 2
- CloudAdapter' object has no attribute 'create_connector_client' HOT 13
- Add connect_named_pipe method to CloudAdapter in support of DirectLine Speech
- Can't deploy echo-bot.py. ModuleNotFoundError: No module named 'aiohttp' HOT 3
- CVE-2020-22083 security vulnerability in botbuilder-python SDK HOT 2
- botbuilder-integration-aiohttp - Python 3.12 compatibility HOT 4
- TeamsChannelAccount model missing aadObjectId
- Bot gives same response multiple times when deployed with azure bot service HOT 4
- BotBuilder-Python SSO not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from botbuilder-python.